Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4029438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:20:43+00:00 2026-05-20T11:20:43+00:00

Today I decided to try to use CALayers to show a rectangular box overlaying

  • 0

Today I decided to try to use CALayers to show a rectangular box overlaying a NSView. The layer will contain some text and will be turned on and off depending on when it is necessary to show the variable text. The reason I wanted to use CALayer for this was the nifty rendering and animation you can easily do with CALayer. I implemented my layer and it worked like a charm. However, after using my GUI and clicking several times on various buttons turning the layer on and off, it seemed that the hierarchy of what I thought was my layer view was skewed. I think focus must have been switched to some other NSView which again was turned off. I basically got very confused as to which layer I was handling at a given time and I lost control of the view hierarchy.

My question is: should I use subviews of NSView, or CALayers to show something that may occur many times on and off in an application? It seems to me that it is easy to loose control of which layer you are working on. Is there a way to identify by name the current layer so you can reuse the layer, or is it best to work with layers, delete them and then re-create the layer the next time you need them?

Thanks for your time. Cheers, Trond

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:20:44+00:00Added an answer on May 20, 2026 at 11:20 am

    FWIW,

    1. I have often turned CALayers “on and off” very quickly, with no problems at all. So you can do that if you want to!

    2. Deleting them and recreating them quickly on the fly, does not seem to cause any problems. (It’s not a big resource user, and I’ve never seen any other problems doing that.) So definitely do that if you want to!

    3. I actually don’t understand what you mean about “naming” layers – of course, as iVars they have a name! You have to name all your CALayers.

    Here’s a typical bit of production code (from a .h file):

    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..
    

    And so on and on. I don’t really see how you can “not” name them, you know!

    Finally,

    4, Don’t forget layers are much “better” than NSViews, because: NSViews have shoddy/buggy relationship between overlapping siblings: they essentially don’t work. Read about that here:
    port an iOS (iPhone) app to mac?

    Hope it helps!

    PS – these may also help with CALayers…

    Exactly what should happen in a CALayer's display/drawRect methods?

    What's the difference and compatibility of CGLayer and CALayer?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've decided today is the day I fix some of my pure functions that
I decided to try project euler problem 17 today, and I quickly wrote a
I just came across Clang/LLVM today , and decided to try it out. My
I am having fun with Visual C++ some time already. And today i decided,
I decided to try to mess around with Git today and try to learn
Ok, I wrote this question up earlier today but I decided to delete it
I've never really bothered with math programming, but today I've decided to give it
Today I was listening to the Hanselminutes show about .NET 3.5 SP1...What's inside ,
Today I had a coworker suggest I refactor my code to use a label
Today at work we came across the following code (some of you might recognize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.