在我的应用程序中,我需要一次显示同一个 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;
}
问题是,如果前一个窗口存在,它会绘制新点,略低于现有窗口的右侧,
有没有我需要设置的属性,问题是,如果之前的位置正好在右上角,那么它会在对角绘制新窗口。