objective-c - 如何有一个投射在 NSView 之外的按钮?
解决方案
如果您必须让视图溢出窗口,则无法使用masksToBound
. CALayer
您需要使用子无边框窗口并正确定位它。
这是一个示例(在 ObjC 中):
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSRect windowFrame = self.window.frame;
NSRect childWindowFrame = {
.origin.x = CGRectGetMidX(windowFrame) - 25,
.origin.y = CGRectGetMinY(windowFrame) - 25,
.size.width = 50,
.size.height = 50,
};
NSWindow *childWindow = [[NSWindow alloc] initWithContentRect:childWindowFrame
styleMask:NSWindowStyleMaskBorderless
backing:NSBackingStoreBuffered
defer:YES];
childWindow.backgroundColor = [NSColor clearColor];
childWindow.contentView.wantsLayer = YES;
childWindow.contentView.layer.backgroundColor = [NSColor redColor].CGColor;
childWindow.contentView.layer.cornerRadius = 25.0;
[self.window addChildWindow:childWindow ordered:NSWindowAbove];
}
此屏幕截图中的红色圆圈是子窗口。
推荐阅读
- ios - 我实现了它在初始阶段工作的 iOS 委托方法
- java - Android - Viewmodel 越来越大
- javascript - 无法完美隐藏同位素
- python - 如何从 `Pool.map()` 解压结果?
- r - 无法在 R 中生成核密度估计器的值
- android - 超过100个点的MapboxMapMatching
- jms - Tibco EMS 连接问题
- xcode - Xcode 编译时间:哪种 Mac 配置可提供明显的最佳性能?
- c# - C# 和 Visual Basic 和 VB 代码结构中的代码等效性
- magento - 使用 SSL 在 CentOS 7、Nginx 和 PHP-FPM 上设置 Varnish