IOS:UIViewImage setAlpha问题
我有这样的代码:
当图像将 alpha 从 0.00 更改为 1.00 时,它会立即发生,而不是在 3 秒内发生,为什么?
- (void) startAnimation{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:1.00];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:0.00];
[UIView commitAnimations];}
I have this code:
when image change alpha from 0.00 to 1.00 it is imediately and not in 3 seconds, why?
- (void) startAnimation{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:1.00];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:0.00];
[UIView commitAnimations];}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个动画都在同一个运行周期中运行(这就是 UIView 动画的工作原理 - 一个运行周期中的所有动画都是“串联的”。
您需要在第二个动画上使用
。罢工>Example Code
There are two ways to do this—using the standard begin/commit animations, or using the blocks method. This example uses the begin/commit animations code, which is what you have. The issue is because the animations are being concatenated, and without going into CA, the standard animation behavior is for one to be "forced" to end before the other runs. It has to do with run loops; Building Animation-Driven Interfaces from WWDC 2010 goes into depth about this. But the code to do what you want looks like this:
基本上,你必须强制它打破运行循环。要记住的关键一点是,动画并不是像您可能期望的代码那样按顺序执行。
基于块的代码如下所示。请注意,我使用的是自动重复选项,它会自动重复动画。请注意,尽管在动画中,您正在设置一个属性,所以默认情况下,动画完成后视图将恢复可见。因此,您需要在完成块中再次将该属性设置为零。
希望这有帮助!
Both animations are run in the same run cycle (that's how UIView animations work—all animations in one run cycle are "concatenated."
You'll need to useOn the second animation.Example Code
There are two ways to do this—using the standard begin/commit animations, or using the blocks method. This example uses the begin/commit animations code, which is what you have. The issue is because the animations are being concatenated, and without going into CA, the standard animation behavior is for one to be "forced" to end before the other runs. It has to do with run loops; Building Animation-Driven Interfaces from WWDC 2010 goes into depth about this. But the code to do what you want looks like this:
You have to force it to break up the run loop, basically. The key thing to remember is that animations are not executed sequentially, as you might expect code to be.
The blocks-based code looks like this. Note that I'm using the autorepeat option, which automatically repeats the animation. Note though that in the animation, you are setting a property, so by default after the animation completes the view will go back to being visible. Therefore, you have the set the property again to zero in the completion block.
Hopefully this helps!