objective-c – PDFView setNeedsDisplay:YES在MacOS Sierra 10
发布时间:2020-12-14 17:19:21 所属栏目:百科 来源:网络整理
导读:我使用[PDFView setNeedsDisplay:YES]让PDF视图重绘,它在OSX 10.9-10.11上运行良好. 但是,除非我放大或缩小PDF页面,否则它不起作用… 还有其他方法可以立即重绘吗?代码如下: NSRect newBounds;NSRect currentBounds;NSRect dirtyRect;NSPoint mouseLoc;NS
我使用[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:无效的上下文0x0和更多无效的上下文0x0警告. 解决方法
我遇到了同样的麻烦.我第一次添加注释时,PDFView会立即在页面上显示该注释.从那时起,添加或删除注释在代码中工作正常但PDFView在我手动滚动视图之前不会显示更改.
从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,但它不是一种可靠的方式来偷偷摸摸,并且通常不应该是这样做的方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |