【发布时间】:2014-09-08 19:59:55
【问题描述】:
我想为 UIButton 的正常状态和突出显示状态之间的过渡设置动画。
我在 IB 中放了 2 张图片作为两种状态的背景,并为 TouchUpInside 事件编写了以下代码:
- (void) animate {
[UIView transitionWithView:self.myButton
duration:2
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{ self.myButton.highlighted = YES; }
completion:^(BOOL finished) {[UIView transitionWithView:self.myButton
duration:2
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{ self.myButton.highlighted = NO; }
completion:nil];}
];
}
这样动画就不会定期启动,尤其是当我快速点击按钮时。
我发现通过在上面的方法前面加上以下内容(链接到 UIButton 代替前一个)动画可以正常工作......但我不明白原因!
有人能解释一下当我添加最后一个方法时到底发生了什么吗?
- (void) firstThis {
[self performSelector: @selector(animate) withObject: nil afterDelay: 0];
}
谢谢, 科拉多
【问题讨论】:
标签: ios objective-c animation uibutton performselector