em70
em70

Reputation: 6081

OSX Lion: different views in fullscreen and in windowed mode

I'm trying to make it so that a certain view contained in a window becomes the main content view when fullscreen mode is toggled and goes back to taking just a portion of the window when the user leaves fullscreen mode.

I've come up with the following:

- (void)windowWillEnterFullScreen:(NSNotification *)notification
{
    NSLog(@"entering fullscreen");
    oldView = [[[NSApplication sharedApplication] mainWindow] contentView];
    [oldView retain];
    [[[NSApplication sharedApplication] mainWindow] setContentView:myViewOfInterest];
}

-(void)windowWillExitFullScreen:(NSNotification *)notification
{
    [[[NSApplication sharedApplication] mainWindow] setContentView:oldView];
}

However this only works for the first bit: the window maximises and the view of interest becomes the only one, but when fullscreen mode is left, the view that was the only one visible in fullscreen mode is no longer in the window.

I'm very new to Objective-C and Cocoa, so could anyone tell me what am I doing wrong?

Thanks in advance!

Upvotes: 1

Views: 488

Answers (1)

CRD
CRD

Reputation: 53000

A view can only be a sub-view to one other view at a time. Your myViewOfInterest is removed as a sub-view (of the view hierarchy) of oldView when you make it the contentView of the window. When you later restore oldView you need to add myViewOfInterest back where it was (and what size it was etc.).

Upvotes: 1

Related Questions