Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa Layer-Backed Views: When can I NOT enable layer-backing on a window content view?

This line appears in Apple's Core Animation docs (link: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/SettingUpLayerObjects/SettingUpLayerObjects.html#//apple_ref/doc/uid/TP40004514-CH13-SW5)

It is recommended that you enable layer support in the content view 
of your window whenever possible.

My question is: When can I NOT do that safely?

Explanation:

I've got a few buttons in my UI that I want to animate (rotate) using Core Animation. To do that, they need to be layer-backed. Right now, I've got just the buttons layer-backed and the rest of my views are not. This is working fine. However, Apple does not elaborate on the sentence above, so I'm worried that the animations may break in future releases because the parent views are not layer-backed.

There are two reasons I do not want to layer-back my entire view hierarchy:

  1. It increases my memory footprint by roughly 230%.
  2. It causes LOTS of minor glitches (especially since I do a lot of custom drawing).

So, is it safe to enable layer-backing for just a few buttons here and there and NOT enable it for the whole view hierarchy, or am I flirting with disaster? Thanks!

like image 853
Bryan Avatar asked Feb 13 '13 01:02

Bryan


1 Answers

Yes, it's fine. I've seen previous docs from Apple that tell you to be sparing in enabling layer backing on your views, for the exact reasons you list.

The whole quote is:

In your nib files, use the View Effects inspector to enable layer support for your views. The inspector displays checkboxes for the selected view and its subviews. It is recommended that you enable layer support in the content view of your window whenever possible.

Does that mean that for any given view, when you bring up the view effects inspector, you get checkboxes for the current view AND all it's subviews? If so, Maybe the docs just mean that you should go to the window's content view and check the layer backing checkbox for each view that needs it there, rather than in the settings for the subviews.

I work mostly with iOS these days, and generally just create an outlet and call setWantsLayer: if I want to animate a Mac OS view.

like image 127
Duncan C Avatar answered Sep 27 '22 18:09

Duncan C