When to use CALayer on Mac / iPhone?

I'm a little confused when I use CALayer on iPhone or Mac, and when not to use it? CoreAnimation works great with my UIView based objects without using CALayer. When is the right time to delve into this class?

+18
objective-c iphone cocoa-touch cocoa core-animation
Sep 19 '09 at 2:56
source share
2 answers

In my tests, UIView and CALayer provide about the same level of performance on the iPhone. As rpetrich notes in his comment, UIViews are a thin shell around CALayers. On Mac, CALayers are much lighter than NSViews.

As Ben points out, you can go beyond the possibilities of implicit animation by working directly with CALayers, even providing some 3-D effects through CATransform3D. In many cases, you can do this even using standard views by accessing the support layer (if the view supports the layer).

Another issue is cross-platform (Mac / iPhone) code. My iPhone app uses the CALayer interface for its basic look, to a large extent, because I can use the same code to draw this interface on my colleague's Mac. As another example, I am directing you to Framework Core Plot , which makes full use of graphics using CALayers and works on both Mac and iPhone. CALayers are almost identical on both platforms, where UIView and NSView have very different interfaces.

+35
Sep 19 '09 at 18:40
source share

If you can do what you want with "implicit animation" (offered by UIKit / AppKit without having to delve into CAs, layers, and animators), then definitely go along this route.

CoreAnimation comes into play when you start using more complex animations, such as non-linear motion or repeating effects, and some synchronized effects. There LOT you can handle it, but it is a pretty powerful tool (with a comparative learning curve, at least compared to the UIKit material).

+4
Sep 19 '09 at 3:22
source share



All Articles