I recently converted one of the views in my OS X application to be layer-level, and everything works well under Mountain Lion, however one of my testers complains that the layers do not display under Snow Leopard. I wrote a small test application to run further tests (source code here ), and this test application also does not work under 10.6.
Here is the main code for the code that sets the layers:
- (id)initWithFrame:(NSRect)frameRect { NSLog(@"initWithFrame"); self = [super initWithFrame:frameRect]; if (self != nil) { srand((unsigned)time(NULL)); _rootLayer = [[CALayer alloc] init]; _rootLayer.delegate = self; _rootLayer.anchorPoint = CGPointMake(0.0, 0.0); _rootLayer.frame = NSRectToCGRect([self bounds]); _rootLayer.needsDisplayOnBoundsChange = NO; _rootLayer.masksToBounds = YES; self.layer = _rootLayer; self.wantsLayer = YES; _backgroundLayer = [[CALayer alloc] init]; _backgroundLayer.delegate = self; _backgroundLayer.anchorPoint = CGPointMake(0.5, 0.5); _backgroundLayer.frame = CGRectInset(NSRectToCGRect([self bounds]), BACKGROUND_INSET, BACKGROUND_INSET); _backgroundLayer.cornerRadius = 5.0; _backgroundLayer.needsDisplayOnBoundsChange = NO; _backgroundLayer.masksToBounds = YES; [_rootLayer addSublayer:_backgroundLayer]; _mouseLayer = [self _createOtherLayer]; _mouseLayer.opacity = 0.5; for (unsigned i = 0; i < NUM_OTHER_LAYERS; i++) _otherLayers[i] = [self _createOtherLayer]; [_backgroundLayer addSublayer:_mouseLayer]; [_rootLayer setNeedsDisplay]; [_backgroundLayer setNeedsDisplay]; [self _positionOtherLayersInRect:frameRect]; _trackingArea = nil; [self updateTrackingAreas]; } return self; }
And here is the method that creates the other layers:
- (CALayer *)_createOtherLayer { CALayer *layer = [[CALayer alloc] init]; layer.delegate = self; layer.anchorPoint = CGPointMake(0.5, 0.5); layer.bounds = CGRectMake(0.0, 0.0, 64.0, 64.0); layer.position = CGPointMake(0.0, 0.0); layer.needsDisplayOnBoundsChange = NO; layer.masksToBounds = YES; layer.shadowColor = CGColorGetConstantColor(kCGColorBlack); layer.shadowOffset = CGSizeMake(2.0, -2.0); layer.shadowRadius = 2.0; layer.shadowOpacity = 1.0; [_backgroundLayer addSublayer:layer]; [layer setNeedsDisplay]; return layer; }
Can someone tell me why these layers do not work under 10.6?
source share