美文网首页
NSWindow 禁用resize

NSWindow 禁用resize

作者: 换个名字而已 | 来源:发表于2017-04-19 09:40 被阅读0次

需要禁止 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有效

相关文章

网友评论

      本文标题:NSWindow 禁用resize

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