动画启用 UIBarButtonItem?
有没有办法以动画方式启用或禁用按钮?我尝试了以下方法但没有成功。我猜测此时启用的属性无法像不透明度那样进行动画处理 - 但我希望我是错的。
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
theButton.enabled = YES;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
我不敢相信没有 setEnabled:(BOOL)enabledAnimated:(BOOL)animated
方法。
Is there a way to animate enabling or disabling a button? I've tried the following with no success. I'm guessing at this point that the enabled property cannot be animated like opacity can – but I hope I'm wrong.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
theButton.enabled = YES;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
I can't believe there isn't a setEnabled:(BOOL)enabled animated:(BOOL)animated
method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这实际上非常简单。
UIView.transitionWithView
可以拍摄任何视图的快照,并从快照交叉溶解到视图的新状态。您可以使用该功能来动画化许多更改,包括enabled
。只需使用视图控制器的视图作为目标视图,指定 TransitionCrossDissolve,然后像平常一样进行动画处理。
This is actually really easy.
UIView.transitionWithView
can take a snapshot of any view and cross-dissolve from the snapshot to the new state of the view. You can use that capability to animate a lot of changes, includingenabled
.Just use the View Controller's view as the target view, specify
TransitionCrossDissolve
, then animate as you would normally.可动画化的属性(通过 UIView beginAnimations:context:)有:frame、bounds、center、transform、alpha(来自 Apple 文档)。
因此,您必须确定您的动画到底是什么(就颜色/alpha/变换动画而言)并创建手动动画(也许您必须使用 CAAnimation 而不是 UIView beginAnimations:context:)
Animatable properties (through UIView beginAnimations:context:) are: frame, bounds, center, transform, alpha (from Apple docs).
So you've to determine what exactly your animation is (in terms of color/alpha/transform animations) and create manual animation (maybe you'll have to use CAAnimation instead of UIView beginAnimations:context:)
您可以将按钮的启用/禁用分解为两个重叠图像之间的不透明度变化,每个图像处于一种状态或另一种状态(即使其看起来像淡入/淡出)。在动画完成处理程序中,您可以执行实际的启用/禁用切换。
You can break down the enable/disable of a button into a change in opacity between two overlapping images each in one state or the other (i.e. make it look like a fade-in/fade-out). In the animation completion handler you can to do the actual enable/disable toggle.
这是一个想法:)
在动画块中,从视图中删除按钮并以禁用状态再次添加它。您可以在这里指定您想要哪种动画。
Here's an idea :)
Within your animation block, Remove the button from view and add it again with disabled state. You can specify what kinda animation you want here..
设置:self.buttonSetEvent.customView.alpha = 0.2;
并尝试这个
Set: self.buttonSetEvent.customView.alpha = 0.2;
and try this