I have a window with text field and bezel button. It's borderless and transparent, but the issue reproduces on any window.
The content view of that window is set in IB to a custom class that draws window's background.
Here's the code:
- (void)drawRect:(NSRect)dirtyRect
{
[NSGraphicsContext saveGraphicsState];
float cornerRadius = 10;
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:self.bounds xRadius:cornerRadius yRadius:cornerRadius];
[path setClip];
NSGradient *gradient = [[NSGradient alloc] initWithColorsAndLocations:
[NSColor colorWithCalibratedRed:0.96f green:0.96f blue:0.96f alpha:1.00f], 0.0f,
[NSColor colorWithCalibratedRed:0.84f green:0.84f blue:0.84f alpha:1.00f], 1.0f,
nil];
[gradient drawInRect:self.bounds angle:270];
[NSGraphicsContext restoreGraphicsState];
}
It causes some really weird artifacts, like disappearing objects or the text field's background changing to window's:
What's going on? I've tried to isolate it, I've been playing around with this "graphics context state saving" thing (which I'm not sure if I understand correctly), but the problem persists.
I have XCode 4.4, SDK is 10.7 (so is my OS), and the deployment target is 10.6. It probably doesn't matter, but I've been doing something similar in the past and I've never had such strange issues.