2016-10-06 51 views
0

我們有一個自定義NSPopUpButtonCell,並重寫這個方法:在10.10中,`-saveGraphicsContext`和`-restoreGraphicsContext`如何引起這些問題?

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

的問題是,當我把這個類到我的項目,它使我的(無關)的觀點另一個disappear--中,贏得了「T得出正確

enter image description here

如果我註釋掉-saveGraphicsState-restoreGraphicsState它的工作原理和正確吸取我的另一個觀點

enter image description here

這裏可能會出現什麼問題?

編輯:踢球是在10.11和10.12的隊友沒有看到這個問題

回答

1

我想你應該叫

[NSGraphicsContext saveGraphicsState]; 

[[NSGraphicsContext currentContext] saveGraphicsState];