PDF ビューを再描画するために使用[PDFView setNeedsDisplay:YES]しましたが、OSX 10.9-10.11 でうまく機能しました。ただし、PDFページをズームインまたはズームアウトしないと機能しません...
すぐに再描画する他の方法はありますか? 以下のコード:
NSRect newBounds;
NSRect currentBounds;
NSRect dirtyRect;
NSPoint mouseLoc;
NSPoint endPt;
// Where is annotation now?
currentBounds = [_activeAnnotation bounds];
// Mouse in display view coordinates.
mouseLoc = [self convertPoint: [theEvent locationInWindow] fromView: NULL];
// Convert end point to page space.
if(activePage == nil)
activePage =[_activeAnnotation page];
_LinePoint= [self convertPoint: mouseLoc toPage: activePage];
endPt = [self convertPoint: mouseLoc toPage: activePage];
if(_selectedIdx == 3) //ink
{
[(PDFAnnotationInk*)_activeAnnotation removeBezierPath:_path];
//endPt.x=_xPoint.x; //竖线
//endPt.y=_xPoint.y; //横线
[_path lineToPoint:endPt]; // 普通笔
[(PDFAnnotationInk*)_activeAnnotation addBezierPath:_path];
[self annotationChanged];
[self setNeedsDisplay:YES];
return;
更新:
setNeedsDispalyの呼び出しが見つかりましたdrawPage:toContext: が、描画コードは機能しません drawPage:toContext:
- (void)drawPage:(PDFPage *)pdfPage toContext(CGContextRef)context
{
[super drawPage: pdfPage toContext:context];
NSBezierPath *line=[NSBezierPath bezierPath];
[line moveToPoint:_xPoint];
[line lineToPoint:NSMakePoint(150, 150)];
[[NSColor redColor] set];
[line setLineWidth:50] ;
[line stroke];
}
デバッグは言ったCGContextSetFillColorWithColor: invalid context 0x0し、より多くのinvalid context 0x0警告。で行っているのdrawPage:toContext:はテストで、BezierPath を使用して線を描画するだけです。