Change self.contentView.layer.maskedCorners in a chidWindow

I have added a NSWindow child to a main NSWindow to simulate a NSDrawer (since it has been deprecated).

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?


Answered by LeonardoDev in 664707022
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.

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];
}



I have noticed that if I turn off the shadow, that square dark border disappears.

drawer.hasShadow = NO;

So now the goal is to get both the shadow and a rounded corner window, without the square border.
Accepted Answer
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.

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];
}



Change self.contentView.layer.maskedCorners in a chidWindow
 
 
Q