当我使用类别方法向我的按钮添加动画时,我无法单击该按钮,似乎它被禁用:
[_compassCalibrateButton pulse:1.5 continuously:YES]; _compassCalibrateButton.userInteractionEnabled=YES;
我有一个UIView类别包含这个:
- (void)pulse:(float)secs continuously:(BOOL)continuously { [UIView animateWithDuration:secs/2 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ // Fade out,but not completely self.alpha = 0.3; } completion:^(BOOL finished) { [UIView animateWithDuration:secs/2 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ // Fade in self.alpha = 1.0; } completion:^(BOOL finished) { if (continuously) { [self pulse:secs continuously:continuously]; } }]; }]; }
解决方法
从文档
During an animation,user interactions are temporarily disabled for
the views being animated. (Prior to iOS 5,user interactions are
disabled for the entire application.) If you want users to be able to
interact with the views,include the
UIViewAnimationOptionAllowUserInteraction constant in the options
parameter.
所以你的代码应该是
- (void)pulse:(float)secs continuously:(BOOL)continuously { [UIView animateWithDuration:secs/2 delay:0.0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^{ // Fade out,but not completely self.alpha = 0.3; } completion:^(BOOL finished) { [UIView animateWithDuration:secs/2 delay:0.0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^{ // Fade in self.alpha = 1.0; } completion:^(BOOL finished) { if (continuously) { [self pulse:secs continuously:continuously]; } }]; }]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。