zoukankan      html  css  js  c++  java
  • macos开发-关闭/最小化/全屏居中处理(仿Mac QQ)

    https://juejin.cn/post/6891900387868672013

    关闭/最小化/全屏居中处理(仿Mac QQ),效果如下

    image-20201106143307906

    //  FSWindowCtl.m
    @interface FSWindowCtl ()<NSWindowDelegate>
    
    @end
    
    @implementation FSWindowCtl
    
    - (void)windowDidLoad {
        [super windowDidLoad];
        [self settingWindowStyle];
    }
    // 设置window样式
    - (void)settingWindowStyle {
        self.window.titlebarAppearsTransparent = YES;
        self.window.titleVisibility = NSWindowTitleHidden;
        self.window.styleMask = NSWindowStyleMaskClosable | NSWindowStyleMaskResizable | NSWindowStyleMaskTitled | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskFullSizeContentView;
        [self.window setMovableByWindowBackground:YES];
        [self updateTitleBarOfWindow:false];
    }
    
    // 修改关闭、最小化、全屏的位置
    - (void)updateTitleBarOfWindow:(BOOL)fullScreen {
        CGFloat kTitlebarH = 54.0;
        CGFloat kFullScreenButtonYOrigin = 3.0;
        NSRect windowFrame = self.window.frame;
        NSView *titlebarContainerView = [self.window standardWindowButton:NSWindowCloseButton].superview.superview;
        NSRect titlebarContainerFrame = titlebarContainerView.frame;
        titlebarContainerFrame.origin.y = windowFrame.size.height - kTitlebarH;
        titlebarContainerFrame.size.height = (CGFloat)kTitlebarH;
        titlebarContainerView.frame = titlebarContainerFrame;
        
        CGFloat buttonX = 12.0;
        NSButton *closeBtn = [self.window standardWindowButton:NSWindowCloseButton];
        NSButton *minimizeBtn = [self.window standardWindowButton:NSWindowMiniaturizeButton];
        NSButton *zoomBtn = [self.window standardWindowButton:NSWindowZoomButton];
        
        for (NSButton *buttonView in @[closeBtn, minimizeBtn, zoomBtn]) {
            NSRect buttonFrame = buttonView.frame;
            buttonFrame.origin.y = fullScreen ? kFullScreenButtonYOrigin : round((kTitlebarH - buttonFrame.size.height)/2.0);
            buttonFrame.origin.x = (CGFloat)buttonX;
            buttonX = buttonFrame.size.width + buttonX + 6;
            [buttonView setFrameOrigin:buttonFrame.origin];
        }
    }
    
    #pragma mark - NSWindowDelegate
    - (void)windowDidEnterFullScreen:(NSNotification *)notification {
        [self updateTitleBarOfWindow:YES];
    }
    
    - (void)windowDidExitFullScreen:(NSNotification *)notification {
        [self updateTitleBarOfWindow:NO];
    }
    
    - (void)windowDidResize:(NSNotification *)notification {
        [self updateTitleBarOfWindow:NO];
    }
    
    @end
    复制代码

    Github Demo


    作者:ForgetSou
    链接:https://juejin.cn/post/6891900387868672013
    来源:掘金
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    国内顺利使用Google的另类技巧
    Java进程间通信
    Java 多线程(七) 线程间的通信——wait及notify方法
    转:关于copy_to_user()和copy_from_user()的一些用法
    转: pthread_detach()函数
    转:pthread_create()
    转: ubuntu配置NFS,挂载开发板
    转:全志A20 GPIO 总结文档
    转:Linux 内核中的 cdev_alloc和cdev_add
    转:1.1 cdev_init cdev_alloc 使用说明
  • 原文地址:https://www.cnblogs.com/itlover2013/p/15371922.html
Copyright © 2011-2022 走看看