UIView animation vs CALayers

I'm struggling with conceptualizing animations with a CALayer as opposed to UIView's own animation methods. Throw " Core Animation " into this and, well, maybe someone can articulate these concepts from a high level so I can better visualize what's happening and why I'd want to migrate UIView animations (which I'm quite familiar with now) to CALayer animations on the iPhone. Every view in Cocoa-Touch automatically gets a layer. And, it seems, you can animate one and/or the other?!? Even mix them together?!? But why? Where's the line? What's the pro/con to each?

The Core Animation Programming Guide immediately jumps into Layer & Timing Classes and I think need to take a step back and understand why these varied pieces exist and how relate to each other.


Use views for control and layers for eye candy. Layers don't receive events so it's easier to use a view for those cases, but when you want to animate a sprite or backgrounds, etc., layers make sense. Events pass right through layers to the backing view so you can have a pretty visual representation without messing up your events. Try to overlay a view that you're just using for visual representation and you'll have to pass tap events through to the underlying view yourself.


An UIView is always rendered to a CALayer . When you use UIView methods to animate a view, you are effectively manipulating the underlying CALayer .

If you need to do simple things, use the UIView methods. For more complex situatins, or if you want layers not associated with any view in particular, use CALayers .


I've done a bunch of apps in the past year. Here's my rule of thumb:

  • Use UIView until it doesn't do what you want.
  • Then move to CoreAnimation. But before you get into it too much...
  • If you write more than a few animations, use Cocos2D.
  • 链接地址: http://www.djcxy.com/p/74158.html

    上一篇: 观察CALayer中的动画属性更改

    下一篇: UIView动画与CALayers