gpt4 book ai didi

objective-c - NSWindow setFrame | NSWindow设置屏幕上的位置

转载 作者:行者123 更新时间:2023-12-03 17:43:41 26 4
gpt4 key购买 nike

在我的应用程序中,我需要一次显示同一 NIB 的多个窗口,并且它将根据计时器关闭/释放,

一切工作正常,除了窗口位置。我的要求是,它应该将窗口显示在前一个窗口的正下方,如果存在相同 NIB 的任何窗口,我能够计算新窗口的原点。

我正在使用这个函数来获取原点:

-(void)awakeFromNib{  

NSString *eventMsg = [NSString stringWithFormat:@"%s is set “,eventName];
[pTextField setStringValue:eventMsg];

[pWindow setFrameOrigin:[self pointstoDisplayScreen]];

/* On timer callback , i will show the fadeout and fadein effects*/
[self startTimer];
}

/* This method returns the coordinate where to
draw the window
*/
-(NSPoint)pointstoDisplayScreen{
NSRect frame = [[NSScreen mainScreen] visibleFrame];
NSRect windowRect = [pWindow frame];

CGFloat yCoordinate = frame.size.height-windowRect.size.height;

NSPoint point = NSMakePoint(frame.size.width - windowRect.size.width, frame.size.height-windowRect.size.height);

/* Let there be some gap, if any window present and let it draw below to
the existing window
*/
point.y -= (windowRect.size.height + windowOffset)*noOfWindow;
NSLog([NSString stringWithFormat:@"PositionToDisplayScreen x = [%f] y = [%f]",point.x,point.y ]);

return point;
}

问题是,如果存在先前的窗口,它会在现有窗口的稍下方和右侧绘制新点,

是否需要设置任何属性,问题是,如果之前的位置正好在右上角,那么它将在对角绘制新窗口。

最佳答案

[NSWindowController setShouldCascadeWindows:NO]; 

通过设置,它可以工作,现在所有通知都绘制在屏幕的右上角。
谢谢。

关于objective-c - NSWindow setFrame | NSWindow设置屏幕上的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5120460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com