在_menuButton的touchUpInside调用中,我执行动画以显示带有完成块的菜单,以将菜单标签从“打开”更改为“关闭”。该动画工作正常,但当你按下_menuButton时,即使用户取消点击或滑出按钮,它也会立即从“关闭”变为“菜单”。按钮标签的初始文本是“menu”。
不确定它是否有所作为,但我对_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";
}];
答案 0 :(得分:1)
将_menuButton.titleLabel.text = @"close";
更改为
[_menuButton setTitle:@"close" forState:normal];
答案 1 :(得分:0)
UIButton提供了询问和设置标题的方法。你要找的是:
- (void)setTitle:(NSString *)title forState:(UIControlState)state