How to make NSView not clip its bounding area? How to make NSView not clip its bounding area? objective-c objective-c

How to make NSView not clip its bounding area?


It turns out that if the line:

((NSView *)self.window.contentView).wantsLayer = YES;

is added to the very beginning, then it works as expected:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{      ((NSView *)self.window.contentView).wantsLayer = YES;    self.view = [[NSView alloc] initWithFrame:NSMakeRect(200, 200, 200, 200)];    self.view.wantsLayer = YES;    self.view.layer.backgroundColor = [[NSColor yellowColor] CGColor];    [self.window.contentView addSubview:self.view];    self.view.layer.anchorPoint = CGPointMake(0.5, 0.5);    self.view.layer.transform = CATransform3DMakeRotation(30 * M_PI / 180, 0, 0, 1);}

So it looks like if all the views are made to be layer backed, then it works the same as it does on iOS. (If there is a quick way to make all views layer backed automatically, that'd be good).

the anchorPoint line cannot be moved before addSubview line, or else it is incorrect, although I wonder why that would make any difference.

The line self.view.layer = [CALayer layer]; can be removed if window.contentView is layer backed. Both the contentView and self.view don't need to set the layer, and I wonder why too.

The transform line cannot be before the addSubview line, or else it won't rotate, and I wonder why too.

The third thing is that, I thought if I go to Interface Builder and make the contentView a class of ContentView (subclassing NSView), and in its init method, do a self.wantsLayer = YES;, then it would work too, but it does not.

But anyway, the code above works, and I will update the reasons above why when I find out more.

enter image description here