动画时设置属性两次
如果我在动画块内将属性两次设置为两个不同的值,会发生什么情况?如果我执行以下伪代码:
myView.frame = CGRectMake(0, 0, 50, 50); // state 0
[UIView beginAnimations:@"showBanner" context:NULL];
{
[UIView setAnimationDuration:2];
myView.frame = CGRectMake(0, 20, 50, 50); // state 1
myView.frame = CGRectMake(0, 10, 50, 50); // state 2
}
[UIView commitAnimations];
我应该得到以下哪个结果?
- 帧从状态 0 通过状态 1 到状态 2 进行动画处理。
- 帧从状态 0 直接进行动画处理到状态 2,忽略状态 1。
我希望结果 #2 发生,因为我认为属性的状态是在动画已提交。我的应用程序中出现的行为似乎表明结果#1 正在发生,因此我提出了问题。
What happens if I set a property twice to two different values inside of an animation block? If I execute the following pseudocode:
myView.frame = CGRectMake(0, 0, 50, 50); // state 0
[UIView beginAnimations:@"showBanner" context:NULL];
{
[UIView setAnimationDuration:2];
myView.frame = CGRectMake(0, 20, 50, 50); // state 1
myView.frame = CGRectMake(0, 10, 50, 50); // state 2
}
[UIView commitAnimations];
which of the following results should I get?
- The frame animates from state 0 through state 1 to state 2.
- The frame animates from state 0 directly to state 2, ignoring state 1.
I would expect result #2 to happen because I would think that the state of the properties is recorded when the animation is committed. I'm getting a behavior in my app which seems to indicate that result #1 is happening, hence my question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(2) 帧从状态 0 直接动画到状态 2,忽略状态 1。
(2) The frame animates from state 0 directly to state 2, ignoring state 1.
我需要这个问题的答案,但没有找到令人满意的答案。我构建了一个快速测试,放置了一个像这样的小子视图:
然后提供了两个像这样的替代动画:
发生的情况如下:在
animateWithSimpleBlock
上,testView 从初始状态跳转到单帧(无动画) 0,0 位置到中间位置 200,200。从那里开始,它会以超过 2 秒的动画时间到达最终的 0,300 位置。但是 animateWithQualifiedBlock 可以将 testView 从最初的 0,0 位置平滑地动画到最终的 0,300 位置。这是我需要的行为(b/c 我正在使用动画块中调用的循环方法构建新的视图位置)。
I needed an answer to this question and didn't find either one given here satisfactory. I built a quick test that placed a small subview like this:
And then provided two alternative animations like this:
Here's what happens: on
animateWithSimpleBlock
, the testView jumps in a single frame (no animation) from it's initial 0,0 position to the intermediate position 200,200. From there, it animates over 2sec to the final 0,300 position.But
animateWithQualifiedBlock
animates the testView smoothly from it's initial 0,0 position to the final 0,300 position. This is the behavior I need (b/c I'm building up new view positions with looping methods called in the animation block).实际上答案是3。以上都不是。
动画块只会为属性的最后一次状态更改提供动画效果。因此,在您的情况下,框架将从状态 1 动画到状态 2。
Actually the answer is 3. None of the above.
The animation block will only animate the last state change for the property. So in your case the frame will animate from state 1 to state 2.