繁体   English   中英

可可调整窗口大小以适合屏幕

[英]Cocoa resize window to fit screen

我有2个监视器,我想将我的videoWindow放置并缩放到第二个监视器的大小。 我想以编程方式执行此操作,因为第二台显示器的分辨率可能会发生变化。 我能够将窗口放置在第二个监视器的左下角,但是我无法缩放它以适合它。

此行的警告:

[self.videoWindow setFrame: screenRect];

是:“ NSWindow”可能不响应“ setFrame”

// inside my .h file
@property (assign) IBOutlet NSWindow *videoWindow;


// inside my .m file
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
    [super windowControllerDidLoadNib:aController];

    NSRect videoPreviewScreenRect;
    NSArray *screenArray = [NSScreen screens];

    //Using index of 1, to get secondary monitor
    NSScreen *videoPreviewScreen = [screenArray objectAtIndex: 1];

    NSRect screenRect = [videoPreviewScreen frame];
    videoPreviewScreenRect = [videoPreviewScreen visibleFrame];

    // Get and set the screen origin based on the second monitors origin
    NSPoint videoScreenOrigin ;
    videoScreenOrigin.x = videoPreviewScreenRect.origin.x;
    videoScreenOrigin.y = videoPreviewScreenRect.origin.y;
    [self.videoWindow setFrameOrigin: videoScreenOrigin];

    // **** THIS LINE DOESN'T WORK ****
    [self.videoWindow setFrame: screenRect];

    [self.videoWindow setBackgroundColor: NSColor.blackColor];
    [self.videoWindow display];
    [self.videoWindow makeKeyAndOrderFront:nil];
}

我能够找出问题所在。

[self.videoWindow setFrame: screenRect];

需要更改为:

[[self videoWindow] setFrame:screenRect display:YES animate:NO]; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM