I have added a NSWindow child to a main NSWindow to simulate a NSDrawer (since it has been deprecated).
Then I animate the drawer to the left/right to open/close it. It works well. Since I need only 2 rounded corners I have setup two conditions: when the drawer opens to the right side of the main window and when it opens to the left side.
It works well at the first settings. If I later change side, as I change the maskedCorners as shown here above, I still see the drawer with the proper rounded corners but I also see an unwanted tiny dark "squared" border around the window, even close to the rounded corners.
How can I update the layer to properly show the rounded corners without that squared border around the whole window?
Code Block [mainWindow addChildWindow:drawer ordered:NSWindowBelow]; drawer.contentView.wantsLayer = YES; drawer.contentView.layer.backgroundColor = [NSColor clearColor].CGColor; drawer.contentView.layer.masksToBounds = YES; drawer.contentView.layer.cornerRadius = 10.0;
Then I animate the drawer to the left/right to open/close it. It works well. Since I need only 2 rounded corners I have setup two conditions: when the drawer opens to the right side of the main window and when it opens to the left side.
Code Block if(drawer.mSide == kSideRight){ drawer.contentView.layer.maskedCorners = kCALayerMaxXMinYCorner | kCALayerMaxXMaxYCorner; } else{ drawer.contentView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMinXMaxYCorner; }
It works well at the first settings. If I later change side, as I change the maskedCorners as shown here above, I still see the drawer with the proper rounded corners but I also see an unwanted tiny dark "squared" border around the window, even close to the rounded corners.
How can I update the layer to properly show the rounded corners without that squared border around the whole window?
I solved the trouble by using a performSelector with a small delay to setup the maskedCorners for the first time.
With this solution I don't see that dark square-window-border close to the maskedCorners.
// On the drawer class I do
With this solution I don't see that dark square-window-border close to the maskedCorners.
Code Block - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { drawer.hasShadow = YES; [drawer setOpaque:NO]; [drawer setBackgroundColor:[NSColor clearColor]]; [drawer setStyleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskFullSizeContentView]; drawer.contentView.wantsLayer = YES; drawer.contentView.layer.frame = drawer.contentView.frame; drawer.contentView.layer.masksToBounds = YES; drawer.contentView.layer.cornerRadius = 10.0; drawer.contentView.layer.backgroundColor = [NSColor clearColor].CGColor; [mainWindow addChildWindow:drawer ordered:NSWindowBelow]; [drawer performSelector:@selector(SetMaskedCorners) withObject:nil afterDelay:0.1]; // instead of [drawer SetMaskedCorners]; }
// On the drawer class I do
Code Block - (void)SetMaskedCorners { if(self.mSide == kSideRight){ self.contentView.layer.maskedCorners = kCALayerMaxXMinYCorner | kCALayerMaxXMaxYCorner; } else{ self.contentView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMinXMaxYCorner; } [self.contentView setNeedsLayout:YES]; }