开发者

How To Disable "Implicit" or Automatic Animations

开发者 https://www.devze.com 2023-03-05 13:35 出处:网络
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 animat

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 ani开发者_StackOverflow中文版mation 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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消