gpt4 book ai didi

xcode - NSWindow 的自定义标题栏

转载 作者:行者123 更新时间:2023-12-04 16:07:11 60 4
gpt4 key购买 nike

Creating a custom title bar on a standard NSWindow 的帮助下,我一直在尝试为 NSWindow 创建自定义标题栏.

NSView *themeFrame = [[window contentView] superview];
NSView *firstSubview = [[themeFrame subviews] objectAtIndex:0];
[titleBarView setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)];
[themeFrame addSubview:titleBarView positioned:NSWindowBelow relativeTo:firstSubview];

它适用于 OSX 10.9,但在 OSX 10.10 中,Xcode 发出警告:

NSWindow warning: adding an unknown subview:XXX
0 AppKit 0x00007fff88f80b3c -[NSThemeFrame addSubview:] + 107
1 AppKit 0x00007fff8896fb8f -[NSView addSubview:positioned:relativeTo:] + 208

应用程序可以正常运行并显示自定义标题,此警告仅在 Xcode 控制台中显示。那么 OSX 10.10 是否在这里做了一些改变?以及添加自定义标题栏的任何新方法?

最佳答案

是的,OS X Yosemite 使用新的 NSTitlebarAccessoryViewController API 来向标题栏添加自定义 subview :

NSWindow has never supported clients adding subviews to anything other than the contentView. Some applications would add subviews to the contentView.superview (also known as the border view of the window). NSWindow will now log when it detects this scenario: "NSWindow warning: adding an unknown subview:". Applications doing this will need to fix this problem, as it prevents new features on 10.10 from working properly. See titlebarAccessoryViewControllers for official API.

NSWindow now has the ability to add officially known subviews to the titlebar/toolbar area. The views are to be wrapped with a new NSViewController subclass called NSTitlebarAccessoryViewController and added to the window with the "titlebarAccessoryViewControllers" API. There are a set of methods to add and insert the titlebarAccessoryViewControllers, such as addTitlebarAccessoryViewController: and removeTitlebarAccessoryViewControllerAtIndex:. However, one can also utilize "removeFromParentViewController" to easily remove a given child view controller. NSTitlebarAccessoryViewController has a property to tell NSWindow where to place the view (layoutAttribute) and a property to determine how it behaves in full screen (fullScreenMinHeight). The NSToolbar fullScreenAccessoryView API is now deprecated, and clients should utilize this new API.

https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/

关于xcode - NSWindow 的自定义标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26924502/

60 4 0