开发者

NSWindow setFrame | setPosition on the screen

In my application, I need to display a multiple window of same NIB, at a time, and it will be closed/released on the timer basis,

everything is working fine, except the window position. My requirement is, it should display the window exactly below the previous window, I am able to calculate origin for the new window if any window of same NIB is present.

I am using this function to get the origin:

-(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];
   开发者_JS百科 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;
}

The problem is if if previous window is present it draws the new point, slightly below and toward right side of the existing window,

Is there any property i need set, the problem is, if the previous position is exactly on the top right, then it draw the new window on the opposite corner.


[NSWindowController setShouldCascadeWindows:NO]; 

By setting this, its working, Now all the notification drawing at the top right corner of the screen.
Thanks.


Your window location is "jumping" because you are not doing any bounds checking to determine that the calculated new origin is within the screen bounds.

The class NSScreen will give you details of the screen(s), for each on you cant get its frame.

Now you need to decide how you want a window origin to move; e.g. to the screen edge and no further, onto an adjacent screen if there is one, wrapping (off right means come on left), etc. The choice will depend on your application.

Armed with the screen frame(s) and the movement algorithm you can calculate your new origin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜