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 7779707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:42:24+00:00 2026-06-01T18:42:24+00:00

This one is stumping me. I have a CALayer which I create in a

  • 0

This one is stumping me. I have a CALayer which I create in a UIViewController‘s viewDidLoad method something like this:

- (void)viewDidLoad {

    [super viewDidLoad];

    UIImage* img = [UIImage imageNamed:@"foo.png"];

    _imageLayer = [[CALayer alloc] init];

    _imageLayer.bounds = CGRectMake( 0, 0, img.size.width, img.size.height);
    _imageLayer.position = CGPointMake( self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0 );

    _imageLayer.contents = (id)img.CGImage;
    _imageLayer.contentsScale = img.scale;

    [self.view.layer addSublayer:_imageLayer];
    [_imageLayer setNeedsDisplay];
}

The UIViewController is loaded from a nib and placed into a UITabBarController that was created in code.

My problem is that the CALayer does not render its UIImage contents when the UIViewController becomes visible. The only way I can make the CALayer to render the UIImage is by setting its contents to the UIImage after the UIViewController is made visible, such as in the viewDidAppear: method.

I would really prefer to do all my set up in the viewDidLoad method (isn’t that what’s it’s for?). How do I get the CALayer to render its contents?

  • 1 1 Answer
  • 0 Views
  • 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-06-01T18:42:25+00:00Added an answer on June 1, 2026 at 6:42 pm

    You don’t need that setNeedsDisplay on the layer, or the superview.

    setNeedsDisplay tells a layer or view that it needs to redraw its contents. (For a view, it will call drawRect: to get new contents; for a CALayer, it will ask its delegate.) Note that this affects only the view or layer itself, not its children.

    Since you are providing the content for the layer directly, you don’t want CA to discard that content and ask for a replacement.

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

Sidebar

Related Questions

I have been using jQuery for some time and this one's stumping me- I
This one is a little tricky to explain. I would like to create a
This one's driving me crazy... I have a loop which adds an event listener
This one has been stumping me for a while. But I'm no expert. This
This one is a real head scratcher for me... var matches = Regex.Matches(<p>test something<script
This one game I do scripting for uses a primary dll in which our
this may seem like a stupid question, but it is stumping me nontheless. I'm
This one is tough to explain inside the title. What I have going on
I've got another simple one (I think) that's stumping me. I have written a
I know a lot about C# but this one is stumping me and Google

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.