Mik*_*zzy 2 iphone animation core-animation button uibarbuttonitem
有没有办法以动画方式启用或禁用按钮?我尝试了以下方法但没有成功。我猜测此时启用的属性无法像不透明度那样进行动画 \xe2\x80\x93\xc2\xa0 但我希望我是错的。
\n\n [UIView beginAnimations:nil context:nil];\n [UIView setAnimationDuration:1.0f];\n theButton.enabled = YES;\n [UIView setAnimationDelegate:self];\n [UIView commitAnimations];\nRun Code Online (Sandbox Code Playgroud)\n\n我不敢相信没有一个setEnabled:(BOOL)enabled animated:(BOOL)animated方法。
这实际上非常简单。UIView.transitionWithView可以拍摄任何视图的快照,并从快照交叉溶解到视图的新状态。您可以使用该功能来动画化许多更改,包括enabled.
只需使用视图控制器的视图作为目标视图,指定TransitionCrossDissolve,然后像平常一样设置动画。
UIView.transitionWithView(self.view,
duration: 0.5,
options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: { () -> Void in
self.someButton.enabled = !self.someButton.enabled
}, completion:nil)
Run Code Online (Sandbox Code Playgroud)