Cocoa App进入全屏

时间:2011-03-09 16:15:40

标签: objective-c cocoa macos

我正在开发一个使用全屏窗口的简单应用程序。

窗口包含包含按钮,图像等的视图......但是当我使用以下行进入全屏时:

NSWindow* tmp = [self window];
    [tmp setStyleMask:NSBorderlessWindowMask];
    [tmp setFrame:[tmp frameRectForContentRect:[[tmp screen] frame]]display:YES animate:NO];
    [tmp setBackingType:NSBackingStoreBuffered];
    screenRect = [[NSScreen mainScreen] frame];
    int windowLevel = CGShieldingWindowLevel();
    [self.window setLevel:windowLevel]; 

我放在窗口中的视图没有自动调整大小,我可以正确调整大小的操作,但是有一种方法可以自动完成吗?

我在这里发布我的所有AppController:

 -(id)init {
    self = [super initWithWindowNibName:@"MainWindow"];

    NSWindow* tmp = [self window];
    [tmp setStyleMask:NSBorderlessWindowMask];
    [tmp setFrame:[tmp frameRectForContentRect:[[tmp screen] frame]]display:YES animate:NO];
    [tmp setBackingType:NSBackingStoreBuffered];
    screenRect = [[NSScreen mainScreen] frame];

  /**   
   //  [[tmp standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
   //  [[tmp standardWindowButton:NSWindowZoomButton] setHidden:YES];

    self.window = [[NSWindow alloc] initWithContentRect:screenRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO screen:[NSScreen mainScreen]];
  **/
    int windowLevel = CGShieldingWindowLevel();
    [self.window setLevel:windowLevel];
    return self;
}


// We need to be layer-backed to have subview transitions.
-(void)awakeFromNib {
    [[self window] setContentSize:[topMenu frame].size];
    [[[self window] contentView] addSubview:topMenu];
    [topMenu enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
    [[[self window] contentView] setWantsLayer:YES];
}


- (void)dealloc
{

    [super dealloc];
}

- (void)windowDidLoad
{
    [super windowDidLoad];

    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.


    [topMenu_controller performAnimation]; 
    return;


}

1 个答案:

答案 0 :(得分:1)

您可以使用Interface Builder的弹簧和支柱来设置视图的自动调整行为:

http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/IB_UserGuide/Layout/Layout.html