OSX Lion: different views in fullscreen and in windowed mode

时间秒杀一切 提交于 2019-12-08 03:41:59

问题


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!


回答1:


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.).



来源:https://stackoverflow.com/questions/9019178/osx-lion-different-views-in-fullscreen-and-in-windowed-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!