UIView animateWithDuration:delay: 工作很奇怪
我在使用 iPhone 动画块时遇到了一个奇怪的问题。 此代码:
[UIView animateWithDuration:2 delay: 0 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor blueColor]]; }
completion: nil];
[UIView animateWithDuration:2 delay: 2 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor redColor]]; }
completion: nil];
立即将背景设置为红色,而不传递蓝色状态。 即使对于此代码也是如此:
[UIView animateWithDuration:2 delay: 0 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor blueColor]]; }
completion:
^(BOOL wrwg) {
[UIView animateWithDuration:2 delay: 2 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor redColor]]; }
completion: nil];
}];
也就是说,我尝试在第一个动画完成后运行第二个动画。 有什么问题吗?
I experience a strange problem with iPhone animation blocks.
This code:
[UIView animateWithDuration:2 delay: 0 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor blueColor]]; }
completion: nil];
[UIView animateWithDuration:2 delay: 2 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor redColor]]; }
completion: nil];
Instantly sets the background to red, without passing the blue state.
The same thing EVEN for this code:
[UIView animateWithDuration:2 delay: 0 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor blueColor]]; }
completion:
^(BOOL wrwg) {
[UIView animateWithDuration:2 delay: 2 options: 0 animations:
^(void) { [controller setBackgroundColor: [UIColor redColor]]; }
completion: nil];
}];
That is, where I try to run the second animation AFTER the first has finished.
What's the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题。确保控制器的类型为 UIView,否则动画块将被解释为“没有要执行的动画”,因此会跳过并渲染下一个动画。
另请参阅这篇文章,我在其中提出了同样的问题(以及我的解决方案):
http://www.iphonedevsdk .com/forum/iphone-sdk-development/64451-animation-one-after-another.html#post265531
I had the same problem. Make shure that controller is of type UIView otherwise the animation block is interpreted as "no animation to perform" and therefore skipped and the next animation is rendered.
Also have look to this post where I asked the same question (with solution by me):
http://www.iphonedevsdk.com/forum/iphone-sdk-development/64451-animation-one-after-another.html#post265531
属性
backgroundColor
在 UIView 中不是动画的。相反,请使用视图层的backgroundColor
属性:PS 正如之前的文章中指出的那样,请确保您的
controller
继承自UIView
。如果它继承自UIViewController
,请改用controller.view
。Property
backgroundColor
is NOT animated in UIView. Instead, usebackgroundColor
property of the view's layer:P.S. As was pointed in previous posts, make sure that your
controller
is inherited fromUIView
. If it is inherited fromUIViewController
, usecontroller.view
instead.我刚刚遇到了这个问题,而且我经常遇到这个问题。有两个原因,尽管其中之一是我尚未测试的。
原因一,我忘记将界面生成器连接到动画视图,因此块显示“Animate on nil?没有什么可做的,所以我要跳到完成块!”
另一个原因是,有一些事情要做,但它不是一个可动画的属性(隐藏),我敢打赌,一旦动画中的变量匹配它们的“to”或“end”状态,就会调用完成块。这只是一个理论,但我敢打赌它是一个单独的线程,以一定的速度执行:
if (currentValueOfProperty = FinalValue) doCompletion()。 (请原谅伪代码)。
不过,也许有人应该测试一下
I just had this issue, and I commonly have it. There are two causes, although one is something I have yet to test.
Cause one, I forgot to hook up interface builder to the animated view, thus the block said "Animate on nil? There's nothing to do, so I'm gonna skip to the completion block!"
The other cause is, there is something to do, but it's not an animatable property (Hidden), and I would bet that the completion block is called as soon as the variables in the animation match their "to" or "end" state. It's just a theory, but I'm betting it's a separate thread that executes at a certain pace with:
if (currentValueOfProperty = finalValue) doCompletion(). (pardon the pseudo code).
Somebody should probably test that, though