我曾经[PDFView setNeedsDisplay:YES]
让 PDF 视图重绘,它在 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 来画一条线。