2016-08-22 3 views
4

NSRectFill (bounds)을 사용하여 rect를 채울 수 있다는 것을 알고 있습니다. 그러나 PDF 출력의 투명성을 유지하기 위해 NSBezierPath (rect : bounds) .fill() 만 사용하면됩니다. 그 둘의 차이점은 무엇입니까?NSRectFill과 NSBezierPath (rect)의 차이점은 무엇입니까?

func drawBackground() { 
    CGContextSaveGState(currentContext) 
    if (NSGraphicsContext.currentContextDrawingToScreen()) { 
     NSColor(patternImage: checkerboardImage).set() 
     NSRectFillUsingOperation(bounds, NSCompositingOperation.CompositeSourceOver) 
    } 
    NSColor.clearColor().setFill() 
    //NSRectFill(bounds) //option 1 
    NSBezierPath(rect: bounds).fill() // option 2 
    CGContextRestoreGState(currentContext) 
} 

extension NSImage { 

    static func checkerboardImageWithSize(size : CGFloat) -> NSImage { 
     let fullRect = NSRect(x: 0, y: 0, width: size, height: size) 
     let halfSize : CGFloat = size * 0.5; 
     let upperSquareRect = NSRect(x: 0, y: 0, width: halfSize, height: halfSize); 
     let bottomSquareRect = NSRect(x: halfSize, y: halfSize, width:halfSize, height: halfSize); 
     let image = NSImage(size: NSSize(width: size, height: size)) 
     image.lockFocus() 
     NSColor.whiteColor() 
     NSRectFill(fullRect) 
     NSColor(deviceWhite: 0.0, alpha:0.1).set() 
     NSRectFill(upperSquareRect) 
     NSRectFill(bottomSquareRect) 
     image.unlockFocus() 
     return image 
    } 
} 
+0

합성 모드가 NSCompositeCopy입니까? NSRectFillUsingOperation이 더 잘 작동 했습니까? – matt

+0

예, 당신은 완전합니다. NSRectFillUsingOperation + CompositeCopy는 NSRectFillUsingOperation + CompositeSourceOver가 NSBezierPath + fill처럼 작동하는 동안 NSRectFill과 동일하게 수행합니다. 대답으로 써보십시오. 나는 당신에게 신용을줍니다. 감사. –

+0

감사합니다. 다행이 다행! – matt

답변

3

나는 주로 사물의 AppKit의 측면에서 이러한 일 아이폰 OS 프로그래머가 아니라 매우 유창 해요,하지만 내 생각은 잘못된 NSCompositingOperation을 얻고있는 것입니다. 나는 NSRectFill이 NSCompositeCopy를 사용한다는 것을 문서에서보고 있습니다. 컴포지트 작업을 지정하는 NSRectFillUsingOperation을 사용하면 더 효과적 일 수 있습니다.

관련 문제