This one is haunting me. I have CALayerone that I create in a method UIViewController viewDidLoadsomething 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];
}
UIViewControllerloaded from nib and placed in UITabBarControllerthat was created in the code.
My problem is that it CALayerdoesn't display content UIImagewhen it becomes visible UIViewController. The only way to do this CALayerfor rendering UIImageis to set its contents to UIImageafter it UIViewControllerbecomes visible, for example, in a method viewDidAppear:.
I would prefer to do everything that was configured in the method viewDidLoad(for what purpose is it needed?). How to get CALayerto display its contents?
source
share