我有用[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;
UPDATE:
我发现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 画一条线。
我也有同样的麻烦。我第一次添加注释时,PDFView
立即在页面上显示该注释。从那时起,添加或删除注释在代码中工作正常,但是PDFView
在我手动滚动视图之前不会显示更改。
From PDFKit
我试过了:
previewView.layoutDocumentView()
for pageIndex in 0...pdf.pageCount - 1 {
let page = pdf.page(at: pageIndex)!
previewView.annotationsChanged(on: page)
}
和来自NSView
我试过了:
previewView.needsDisplay = true
previewView.needsLayout = true
previewView.documentView?.needsDisplay = true
previewView.updateLayer()
但没有运气。我尝试过滚动PDFView
也可以使用代码,但这并不是偷偷刷新的可靠方法,而且通常不应该是这样做的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)