如何禁用“隐式”或自动动画

发布于 2024-11-07 06:48:00 字数 310 浏览 4 评论 0原文

我的代码遇到了一些障碍。我正在使用 OpenFlow——Apple coverflow 的替代方案,目前免费供开发人员使用。在演示中,一切似乎都运行良好。 “流”是通过使用 UIView 动画来实现动画的。

我已对该演示进行了调整,使其能够在 iPad 上运行。一切都运行良好,除了由于某种原因视图现在隐式动画之外。我不明白这是为什么。我什至不认为 iOS 中可以使用隐式动画。

我确实需要一些帮助来弄清楚为什么会发生这种情况,以及如何禁用它们。

I have run into a bit of a snag in my code. I am using OpenFlow—an Apple coverflow alternative currently free for developers to use. In the demo everything seems to work great. The "flow" is animated by using UIView animations.

I have adapted the demo to work on the iPad. Everything works well except that for some reason the views now animate implicitly. I can't figure out why this is. I didn't even think that implicit animation was available in iOS.

I could really use some help figuring out why this is happening in the first place, and how I can disable them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酒忠诚 2024-11-14 06:48:00

好吧,经历了很多头痛和浪费了很多时间之后,我弄清楚了我的代码到底发生了什么。我以为我正在经历隐式动画,但我不明白为什么会突然发生这种情况。

我决定更好地尝试理解隐式动画,因此我自己进行了实验,以找出如何在受控情况下实现它们。我从未见过隐式动画发生的原因是因为我总是使用 UIView 或其子类之一。

我了解到,如果您从 CALayer 开始并严格使用图层,则对许多属性的所有更改都将隐式动画化。

当您看到 UIView(及其后代)全部自动支持图层并具有 CALayer 属性时,可能会有些困惑(我知道我也有过这种困惑)。

尽管如此,很明显 UIView 在某种程度上覆盖了其 CALayer 属性的隐式动画机制。因此,如果您想要隐式动画,则必须直接使用 CALayer,而不仅仅是假设因为 UIView 有 CALayer 属性,它的行为就会相同。

至于我遇到的错误......这可能是我遇到过的最奇怪的错误。无论我尝试什么,一切都是在没有任何动画代码的情况下对值的任何更改进行动画处理。罪魁祸首最终是一个嵌套的 UIView 动画块。

请注意以下内容,看看您是否立即发现问题:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.2];
//animate something
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:.8];
[UIView setAnimationDuration:.4];
//animate something else
[UIView commitAnimations];

我无法使用另一个 [UIView commitAnimations] 终止嵌套块。它确实在我的程序中泄漏了动画。一切都是动画,甚至是完全不同的类中的代码。这个错误已被解决...继续下一个!

Alright, many headaches and much wasted time later, I figured out what the heck was going on in my code. I thought I was experiencing implicit animations, but I couldn't figure out why this started happening all of the sudden.

I decided I better try to understand implicit animations, so I experimented on my own to figure out how to achieve them in a controlled situation. The reason I have never seen implicit animations happen is because I am always using UIView or one of its subclasses.

I learned that if you start with a CALayer and work strictly with the layer, all changes to many of the properties will implicitly animate.

There may be some confusion (I know there was for me) when you see that UIView's (and their posterity) all are automatically layer backed and have a CALayer property.

Never-the-less, it is evident that UIView is somehow overriding the implicit animation mechanism of its CALayer property. So if you want implicit animations, you must use CALayer's directly, not just suppose that because UIView has a CALayer property that it will behave the same.

As for the bug I was experiencing...It was perhaps the strangest one I have yet come across. Everything, no matter what I tried, was animating any changes to values without any animation code. The culprit ended up being a nested UIView animation block.

Notice the following and see if you catch the issue right off:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.2];
//animate something
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:.8];
[UIView setAnimationDuration:.4];
//animate something else
[UIView commitAnimations];

I failed to terminate the nested block with another [UIView commitAnimations]. It was literally leaking animation in my program. Everything was animating, even code in completely different classes. This bug is squashed...on to the next!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文