我们有一个 custom NSPopUpButtonCell
,并覆盖了这个方法:
- (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
{
[[NSGraphicsContext currentContext] saveGraphicsState];
CGFloat strokeWidth = 1;
cellFrame = NSInsetRect(cellFrame, strokeWidth/2.0, strokeWidth/2.0);
NSBezierPath* rectanglePath = [NSBezierPath bezierPathWithRoundedRect:cellFrame xRadius:2 yRadius:2];
rectanglePath.lineWidth = strokeWidth;
if (self.horizontalImageOffset != 0)
{
CGRect stateImageRect = [self stateImageRectForBounds:cellFrame];
CGFloat verticalSeparatorX = NSMaxX(stateImageRect);
NSBezierPath* verticalSeparator = [NSBezierPath bezierPath];
[verticalSeparator moveToPoint:NSMakePoint(verticalSeparatorX, NSHeight(cellFrame) - strokeWidth)];
[verticalSeparator lineToPoint:NSMakePoint(verticalSeparatorX, strokeWidth + 1)];
verticalSeparator.lineWidth = strokeWidth;
[verticalSeparator stroke];
}
[NSGraphicsContext restoreGraphicsState];
}
问题是,当我将这个类带入我的项目时,它会使我的另一个(不相关的)视图消失——例如,无法正确绘制
如果我注释掉它-saveGraphicsState
并且-restoreGraphicsState
它可以正常工作并正确绘制我的其他视图
这里可能出了什么问题?
编辑:踢球者是 10.11 和 10.12 上的队友没有看到这个问题