NSWindow 禁用resize

需要禁止 Mode 显示的NSWindow的zoom功能,网上找了资料基本上都用下面代码

1[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];

2[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];

其他可能被隐藏的标准按钮包括:

1NSWindowCloseButton,

2NSWindowMiniaturizeButton,

3NSWindowZoomButton,

4NSWindowToolbarButton,

5NSWindowDocumentIconButton

此方法只是隐藏了 标题栏的按钮,并没有禁用resize或zoom 功能

因此翻看NSWindow官方文档找到了 NSWindow styleMask属性

@property NSWindowStyleMask styleMask;

typedef NS_OPTIONS(NSUInteger, NSWindowStyleMask) {

NSWindowStyleMaskBorderless = 0,

NSWindowStyleMaskTitled = 1 << 0,

NSWindowStyleMaskClosable = 1 << 1,

NSWindowStyleMaskMiniaturizable = 1 << 2,

NSWindowStyleMaskResizable = 1 << 3,

/* Specifies a window with textured background. Textured windows generally don't draw a top border line under the titlebar/toolbar. To get that line, use the NSUnifiedTitleAndToolbarWindowMask mask.

*/

NSWindowStyleMaskTexturedBackground = 1 << 8,

/* Specifies a window whose titlebar and toolbar have a unified look - that is, a continuous background. Under the titlebar and toolbar a horizontal separator line will appear.

*/

NSWindowStyleMaskUnifiedTitleAndToolbar = 1 << 12,

/* When set, the window will appear full screen. This mask is automatically toggled when toggleFullScreen: is called.

*/

NSWindowStyleMaskFullScreen NS_ENUM_AVAILABLE_MAC(10_7) = 1 << 14,

/* If set, the contentView will consume the full size of the window; it can be combined with other window style masks, but is only respected for windows with a titlebar.

Utilizing this mask opts-in to layer-backing. Utilize the contentLayoutRect or auto-layout contentLayoutGuide to layout views underneath the titlebar/toolbar area.

*/

NSWindowStyleMaskFullSizeContentView NS_ENUM_AVAILABLE_MAC(10_10) = 1 << 15,

/* The following are only applicable for NSPanel (or a subclass thereof)

*/

NSWindowStyleMaskUtilityWindow = 1 << 4,

NSWindowStyleMaskDocModalWindow = 1 << 6,

NSWindowStyleMaskNonactivatingPanel = 1 << 7, // Specifies that a panel that does not activate the owning application

NSWindowStyleMaskHUDWindow NS_ENUM_AVAILABLE_MAC(10_6) = 1 << 13 // Specifies a heads up display panel

};

可以通过设置这个属性来确定NSWindow支持的 style,

self.view.window.styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable;

将 NSWindowStyleMaskResizable 取反则可以实现禁止 双击,菜单栏,标题栏的缩放功能

问题: styleMask 属性 不要在viewDidLoad设置,设置无效。在viewWillAppear或者viewDidAppear有效

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • // //UIView.h //UIKit // //Copyright (c) 2005-2015 Apple ...
    李某lkb阅读 1,775评论 0 0
  • 有一天傍晚,吃过晚饭,一家人都在客厅里。8岁的小悠和5岁的小豆,姐弟俩一起在玩粘土,他们说要做两条五彩毛毛虫;他们...
    江南无所有阅读 493评论 1 1
  • 是吧,写日志的习惯,很久很久了。 悲哀的是,放完暑假回来,蓝色本子的日记本忘记了密码。 任凭怎么想怎麽推敲都找不回...
    一只默阅读 209评论 0 0