我有两台显示器,我希望将我的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];
}
答案 0 :(得分:1)
我能够弄清楚问题是什么。
[self.videoWindow setFrame: screenRect];
需要更改为:
[[self videoWindow] setFrame:screenRect display:YES animate:NO];