美文网首页
设置modal window的位置

设置modal window的位置

作者: 皮蛋豆腐酱油 | 来源:发表于2019-12-17 17:41 被阅读0次

    重写window的center方法,在[[NSApplication sharedApplication] runModalForWindow:];之前,把window的minX和minY赋值。

    https://developer.apple.com/documentation/appkit/nsapplication/1428436-runmodalforwindow?changes=_2&language=objc
    文档里面说的:The window to be displayed modally. If it is not already visible, the window is centered on the screen using the value in its center method and made visible and key. If it is already visible, it is simply made key.

    @interface AlertWindow : NSWindow
    @property (nonatomic, assign) float minX;
    @property (nonatomic, assign) float minY;
    @end
    
    
    #import "AlertWindow.h"
    
    @implementation AlertWindow
    
    - (void)center {
        if (self.minX && self.minY) {
            [self setFrameOrigin:NSMakePoint(self.minX, self.minY)];
        } else {
            [super center];
        }
        
    }
    

    相关文章

      网友评论

          本文标题:设置modal window的位置

          本文链接:https://www.haomeiwen.com/subject/aqhenctx.html