Re: CALayers Lost After Switching Window's ContentView
Re: CALayers Lost After Switching Window's ContentView
- Subject: Re: CALayers Lost After Switching Window's ContentView
- From: Bridger Maxwell <email@hidden>
- Date: Mon, 16 Feb 2009 01:15:45 -0700
Hmm, I don't quite understand the question. Let me elaborate on what is
going on, and hopefully it will clear up.
I have a window that hosts a contentView, which holds many subviews, which
hold subviews themselves. Some of these subviews are being used to display
Core Animation content. I set their setWantsLayer to YES, and then add
sublayers to the layer backing the view. I thought this was the standard
(only) way to use Core Animation. So yes, I am "fiddling" with they layer of
the layer-backed view by adding sublayers, but I didn't know there was any
other way.
After I switch the contentView from one window to another, the Core
Animation stuff disappears. It seems that all of the sublayers (of the layer
backing the view) have been removed. This is not because the layer backing
the view has changed though, it still as the same pointer value.
Here is the code where I set up the Core Animation stuff. This is from the
awakeFromNib of a custom view I have. If I am doing it wrong, I would sure
like to know!
- (void)awakeFromNib {
[self setWantsLayer:YES];
maskLayer = [[CALayer alloc] init];
maskLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
maskLayer.contentsGravity = kCAGravityResizeAspect;
maskLayer.frame = self.layer.bounds;
colorLayer = [[CALayer alloc] init];
colorLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
colorLayer.frame = self.layer.bounds;
colorLayer.mask = maskLayer;
[self.layer addSublayer:colorLayer];
shipLayer = [[CALayer alloc] init];
shipLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
shipLayer.contentsGravity = kCAGravityResizeAspect;
shipLayer.frame = self.layer.bounds;
[self.layer addSublayer:shipLayer];
}
Thank You,
Bridger Maxwell
On Sun, Feb 15, 2009 at 4:25 PM, Scott Anguish <email@hidden> wrote:
> It's hard to tell from this...
>
> are you attempting to manually fiddle with (add layers, etc..) the layer of
> a layer-backed view?
>
> You shouldn't do that. It isn't yours. Only interact with the layers if
> you're using views for layer-hosting
>
>
>
> On 14-Feb-09, at 6:19 PM, Bridger Maxwell wrote:
>
> Hey,
>> I have an application which must switch in and out of full screen mode.
>> Going full screen is fine, but when I exit full-screen, my Core Animation
>> components disappear! Some debugging shows that the CALayer that backs the
>> view is still there and hasn't changed, but all of its sublayers have been
>> removed. I have no idea why this would happen though. To go full screen, I
>> make a new window and make it large and then switch the contentview from
>> the
>> old window to the full screen window and vice-versa for returning to
>> normal
>> mode. I don't see any reason why starting in normal mode and going full
>> screen works fine, but the other way around messes with my Core Animation
>> layers. Here is my go full screen code:
>>
>> (regularWindow is an IBOutlet hooked up to a window in the application's
>> nib
>> file. fullScreenWindow is just an NSWindow instance variable)
>>
>> - (void)enterFullScreen {
>> if (!isFullScreen) {
>> // Capture the main display
>> if (CGDisplayCapture( kCGDirectMainDisplay ) != kCGErrorSuccess) {
>> NSLog( @"Couldn't capture the main display" );
>> }
>> // Put up a new window
>> if (!fullScreenWindow) {
>> fullScreenWindow = [[SCWindow alloc] initWithContentRect:[[NSScreen
>> mainScreen] frame]
>> styleMask:NSBorderlessWindowMask
>> backing:NSBackingStoreBuffered
>> defer:NO screen:[NSScreen mainScreen]];
>> }
>>
>> [fullScreenWindow setLevel:CGShieldingWindowLevel()];
>> [fullScreenWindow setContentView:fullScreenView];
>> [fullScreenWindow makeKeyAndOrderFront:nil];
>> [regularWindow orderOut:self];
>> isFullScreen = YES;
>> }
>> }
>>
>> - (void)exitFullScreen {
>> if (isFullScreen) {
>> // Release the display(s)
>> if (CGDisplayRelease( kCGDirectMainDisplay ) != kCGErrorSuccess) {
>> NSLog( @"Couldn't release the display(s)!" );
>> }
>> [regularWindow setContentView:fullScreenView];
>> [regularWindow makeKeyAndOrderFront:nil];
>>
>> [fullScreenWindow orderOut:self];
>> isFullScreen = NO;
>> }
>> }
>>
>>
>>
>> Thank You,
>> Bridger Maxwell
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden