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 하위 클래스에서 호출되지 않는 이유가 있습니까?
이것은 정확히 내가 필요로했던 도움이었습니다. 고맙습니다! – colincameron