在 _menuButton 的 touchUpInside 调用中,我执行动画以显示带有完成块的菜单,以将菜单的标签从“打开”更改为“关闭”。该动画效果很好,但是当您按下 _menuButton 时,即使用户取消点击或滑出按钮,它也会立即从“关闭”变为“菜单”。按钮标签的初始文本是“菜单”。
不确定它是否有区别,但我的 _menuButton 属性是:
@property (weak, nonatomic) IBOutlet UIButton *menuButton;
动画加载菜单:
[UIView animateWithDuration:0.50
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_menuButton.center = CGPointMake(_menuButton.center.x + 120, _menuButton.center.y);
_quitButton.center = CGPointMake(_quitButton.center.x + 215, _quitButton.center.y);
_rulesButton.center = CGPointMake(_rulesButton.center.x + 215, _rulesButton.center.y);
_preferencesButton.center = CGPointMake(_preferencesButton.center.x + 215, _preferencesButton.center.y);
_quitButton.alpha = 1.0f;
_rulesButton.alpha = 1.0f;
_preferencesButton.alpha = 1.0f;
_menuButton.alpha = 1.0f;
} completion:^(BOOL finished) {
_menuButton.titleLabel.text = @"close";
}];
动画卸载菜单:
[UIView animateWithDuration:0.50
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
_menuButton.center = CGPointMake(_menuButton.center.x - 120, _menuButton.center.y);
_quitButton.center = CGPointMake(_quitButton.center.x - 215, _quitButton.center.y);
_rulesButton.center = CGPointMake(_rulesButton.center.x - 215, _rulesButton.center.y);
_preferencesButton.center = CGPointMake(_preferencesButton.center.x - 215, _preferencesButton.center.y);
_quitButton.alpha = 0.0f;
_rulesButton.alpha = 0.0f;
_preferencesButton.alpha = 0.0f;
_menuButton.alpha = 0.6f;
} completion:^(BOOL finished) {
_menuButton.titleLabel.text = @"menu";
}];