SetWantsLayer changes the behavior of NSWindow

I had a problem with NSWindowand this content view - with the appearance of the title and rounded bottom corners. I am watching problem 10.11, and 10.10 everything looks good. But to the point.

The title bar of the window is as follows:

correct byte titlte

and at the same time, the bottom looks like this:

enter image description here

No rounded corners. The window is launched programmatically and consists of two subqueries added programmatically using the self.contentView addSubview: method.

After some work, it turned out that adding

[self.contentView setWantsLayer:YES]; 

at the beginning of the init window, the line looks like this:

enter image description here

Flat and hard, darker than normal color - not very good. On the other hand, at the bottom it looks like I need it to look like this:

enter image description here

. init :

[self.contentView setWantsLayer:YES];

self.identifier = someid;
self.styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
self.backingType = NSBackingStoreBuffered;
[self setFrame:NSMakeRect(0, 0, windowInitWidth, windowInitHeight) display:NO];
[self setBackgroundColor:[NSColor colorForKeyPath:@"blackcolor"]];
NSButton *windowButton = [self standardWindowButton:NSWindowCloseButton];
[windowButton setEnabled:NO];
[self centerOnMainWindowScreen];

[self setupLeftPanel];
[self setupRightPanel];
[self setupConstraints];

, , ( ?) , . : 10.10 . 10.11 .

+4
2

, , , . , . , ( , ), - , ​​.

, , , , , window contentView .

0

, ( macOS 10.12.2), . swift:

import Cocoa

let window = NSWindow()
window.setContentSize(NSSize(width: 100, height: 100))
window.center()

let layeredView = NSView(frame: window.contentView!.frame)
layeredView.autoresizingMask = [.viewWidthSizable, .viewHeightSizable]
layeredView.wantsLayer = true
layeredView.layer!.backgroundColor = NSColor.blue.cgColor
window.contentView!.addSubview(layeredView)

window.makeKeyAndOrderFront(nil)

NSApplication.shared().run()
0

All Articles