`-saveGraphicsContext` 和 `-restoreGraphicsContext` 的存在如何导致 10.10 中出现这些问题?

How could the existence of `-saveGraphicsContext` and `-restoreGraphicsContext` be causing these issues in 10.10?

我们有一个自定义 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];
}

问题是,当我将此 class 引入我的项目时,它使我的另一个(不相关的)视图消失了——例如,无法正确绘制

如果我注释掉 -saveGraphicsState-restoreGraphicsState 它会起作用并正确绘制我的另一个视图

这里可能出了什么问题?

编辑:奇怪的是 10.11 和 10.12 的队友没有看到这个问题

我想你应该打电话给

[NSGraphicsContext saveGraphicsState];

没有

[[NSGraphicsContext currentContext] saveGraphicsState];