Subview NSView or CALayer?

Today I decided to try using CALayers to show a rectangular frame superimposed on the NSView. The layer will contain text and will be turned on and off depending on when the variable text needs to be displayed. The reason I wanted to use CALayer for this is the excellent rendering and animation that you can easily do with CALayer. I implemented my layer and it worked like a charm. However, after using my graphical interface and pressing several times on different buttons to turn the layer on and off, it seemed that the hierarchy of what I considered the view of my layer was distorted. I think the focus should be switched to another NSView that has been disabled again. I was mostly very confused as to which layer I was processing at a given time,and I lost control of the view hierarchy.

My question is: should subviews NSView or CALayers be used to show something that can appear many times in the application and turn off in the application? It seems to me that it's easy to control which layer you're working on. Is there a way to identify the current layer by name so that you can reuse that layer or work with layers better, delete them and then re-create the layer the next time you need them?

Thank you for your time. Cheers, Trond

+3
source share
1 answer

FWIW,

  • I often turn CALayers on and off very quickly, no problem. So you can do it if you want!

  • . ( , , .) , !

  • , "" - , , iVars ! CALayers.

( .h):

CALayer         *rearLayer;
CALayer         *hugeBasket;        // holds everything for ez-on/off
CALayer         *theActualSkyline;  // nb, same name as similar UIView
CALayer         *someTrees;         // minor stuff
CALayer         *someBushes;        // overs

// for the stupid help basket..
CALayer         *LLDRear;
CALayer         *LLDArrowLeft;
CALayer         *LLDArrowRight;
CALayer         *LLDPointlessUpArrow;
CALayer         *LLDYetAnotherStupidShadow;

// etc etc..

. , "" , !

,

4. , "", NSViews, : NSViews / : . : iOS (iPhone) Mac?

, !

PS - CALayers...

CALayer/drawRect?

CGLayer CALayer?

+9

Source: https://habr.com/ru/post/1796551/


All Articles