views:

397

answers:

2

I'm working on a Snow Leopard app and I'm doing some view animations (swapping them) and I've seen some older examples using NSViewAnimation. I'm wondering if these are completely obsoleted by Core Animation?

It seems fairly simple for me to use

[[myView animator] setFrame:newSwapFrame];

But I'm just wondering if I'm missing something, or if NSViewAnimation is still relevant (other than for backwards compatibility).

+4  A: 

Generally you should move to Core Animation for 10.5+ code. NSViewAnimation is fairly primitive and doesn't make as efficient use of the hardware. I can't think of any advantages of staying with NSViewAnimation other than 10.4 compatibility.

Rob Napier
+2  A: 

There are some cases where Core Animation is not suitable. For example, you can't put a WebView in a layer-backed view without funky things happening.

Also, text fields in layer-backed views don't use subpixel anti-aliasing, which can be a deal breaker.

If you're not using layer-backed views then your example of just using the animatable property support is definitely easier than using NSAnimation.

Rob Keniger
As I'm profoundly more experienced with UIKit and its animation techniques, what's the difference on the Mac between using Layer-backed views and simply just using the `animator` of a view?
jbrennan
The animator proxy doesn't have anything to do with CoreAnimation. A non-layer-backed NSView supports it just about as well as layer-backed views do.
kperryua
As a note, text fields in layer-backed views can use subpixel antialiasing. You need to set the text field's backgroundColor to an opaque color and set the drawsBackground property to YES. See here: http://www.cocoabuilder.com/archive/message/cocoa/2008/3/28/202581
Brad Larson
Yes, I know that you can add a background to the NSTextField and it will look OK. But what I said still stands, you can't use an NSTextField on a layer-backed view in many situations without the text looking rubbish. If the background is an image or other custom drawing, you can't add a background and the only workaround to get the text looking decent is to use a CATextLayer instead.
Rob Keniger
@kperryua, the original poster asked about Core Animation vs. NSViewAnimation. Layer-backed views are part of Core Animation, at least they are in my book, as is the animator proxy.
Rob Keniger
@jbrennan you can use the animator proxy of a "normal" view without a problem. You might use layer-backed views for views containing controls that you need to animate with high performance, as animation of layer-backed views is offloaded to the GPU. This doesn't happen with non-layer-backed views animated using the animator proxy.
Rob Keniger
@Rob: So if my view is layer-backed (because say I've got lots of subviews, thus they will become layer-backed as well), then the animation done through the proxy will be offloaded to the GPU? Are CAAnimations/Other CAThings just for when you want to do really advanced things?
jbrennan
It depends what you're animating. If you're changing the content of the view then the GPU can't animate that as the bitmap for the layer needs to be calculated then re-copied to the GPU. If you're moving, rotating, changing alpha etc then this is definitely GPU-accelerated with layer-backed views.
Rob Keniger