2013-03-07 7 views
0

사용자 정의 PDFView 하위 클래스가 있으며보기 위에 사각형을 그리려면 -mouseDown,등을 재정의했습니다. 여기에 내가 사용하고있는 코드입니다 :PDFView 하위 클래스에서 drawRect가 호출되지 않습니다.

@implementation MyPDFView { 
    NSPoint clickLocation; 
    NSRect selection; 
} 

- (void)mouseDown:(NSEvent *)theEvent { 
    NSPoint clickLocationOnWindow = [self.window mouseLocationOutsideOfEventStream]; 
    clickLocation = [self convertPoint:clickLocationOnWindow fromView:nil]; 

    NSLog(@"%@", NSStringFromPoint(clickLocation)); 
} 

- (void)mouseDragged:(NSEvent *)theEvent { 
    NSPoint mouseLocationOnWindow = [self.window mouseLocationOutsideOfEventStream]; 
    NSPoint currentLocation = [self convertPoint:mouseLocationOnWindow fromView:nil]; 

    CGFloat lowerX = fmin(clickLocation.x, currentLocation.x); 
    CGFloat lowerY = fmin(clickLocation.y, currentLocation.y); 
    CGFloat upperX = fmax(clickLocation.x, currentLocation.x); 
    CGFloat upperY = fmax(clickLocation.y, currentLocation.y); 

    selection = NSMakeRect(lowerX, lowerY, upperX-lowerX, upperY-lowerY); 

    [self setNeedsDisplay:YES]; 

    NSLog(@"%@", NSStringFromRect(selection)); 
} 

- (void)drawRect:(NSRect)dirtyRect 
{ 
    // Drawing code here. 
    NSLog(@"drawRect"); 

    NSBezierPath *bp = [NSBezierPath bezierPathWithRect:selection]; 
    [[NSColor blueColor] set]; 
    [bp fill]; 
} 

@end 

NSRect이 올바르게 계산은,하지만 난 [self setNeedsDisplay]를 호출 할 때, -drawRect가 호출되지 않습니다, 그리고 사각형이 그려지지 않습니다.

-drawRect이 PDFView 하위 클래스에서 호출되지 않는 이유가 있습니까?

답변

1

비슷한 사용 사례가 있습니다. 문서에 따르면 PDFView의 drawPage 메서드를 대신 정의하십시오. PDFView에서 setNeedsDisplay를 계속 호출합니다. 그것은 효과가 있지만 조금 느립니다. 지금 대신보기 오버레이 작업.

+0

이것은 정확히 내가 필요로했던 도움이었습니다. 고맙습니다! – colincameron