Setting NSWindow position in current screen

心不动则不痛 提交于 2019-12-12 17:00:25

问题


I am newbie in objective-c.I have created a main window which I want to display in the right bottom of the current screen. I tried the following code

- (void)windowDidLoad
{
    NSPoint pos;

    pos.x = [[NSScreen mainScreen] visibleFrame].origin.x + [[NSScreen mainScreen] visibleFrame].size.width - [mywindow frame].size.width ;

    pos.y = [[NSScreen mainScreen] visibleFrame].origin.y + [[NSScreen mainScreen] visibleFrame].size.height - [mywindow frame].size.height;

    [mywindow setFrameTopLeftPoint:pos];

}

what is wrong with in it? How to resolve it?


回答1:


Use

NSPoint pos; 
pos.x = [[NSScreen mainScreen] frame].size.width - [mywindow frame].size.width ;

pos.y = 0.0f;

[self.window setFrame:CGRectMake(pos.x, pos.y, [mywindow frame].size.width , [mywindow frame].size.height) display:YES];

Because [[NSScreen mainScreen] frame].origin.x will always be 0. And in case of mac screen starts from bottom.



来源:https://stackoverflow.com/questions/24512553/setting-nswindow-position-in-current-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!