iOS   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – PDFView setNeedsDisplay:YES在MacOS Sierra 10.12上不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我使用[PDFView setNeedsDisplay:YES]让PDF视图重绘,它在OSX 10.9-10.11上运行良好. 但是,除非我放大或缩小PDF页面,否则它不起作用… 还有其他方法可以立即重绘吗?代码如下: NSRect newBounds; NSRect currentBounds; NSRect dirtyRect; NSPoint mouse
我使用[PDFView setNeedsDisplay:YES]让PDF视图重绘,它在OSX 10.9-10.11上运行良好.
但是,除非我放大或缩小PDF页面,否则它不起作用… @H_673_20@ @H_673_20@还有其他方法可以立即重绘吗?代码如下:

@H_673_20@
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;
@H_673_20@更新:

@H_673_20@我发现setNeedsDispaly调用drawPage:toContext:但是绘图代码在drawPage:toContext中不起作用:

@H_673_20@
- (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];
}
@H_673_20@调试说CGContextSetFillColorWithColor:无效的上下文0x0和更多无效的上下文0x0警告.
我在drawPage中做了什么:toContext:正在测试并且只是使用BezierPath来绘制一条线.

解决方法

@H_403_30@ 我遇到了同样的麻烦.我第一次添加注释时,PDFView会立即在页面显示该注释.从那时起,添加删除注释在代码中工作正常但PDFView在我手动滚动视图之前不会显示更改. @H_673_20@ @H_673_20@从PDFKit我尝试过:

@H_673_20@
previewView.layoutDocumentView()

for pageIndex in 0...pdf.PageCount - 1 {
  let page = pdf.page(at: pageIndeX)!
  previewView.AnnotationsChanged(on: pagE)
}
@H_673_20@从NSView我尝试过:

@H_673_20@
previewView.needsDisplay = true
previewView.needsLayout = true
previewView.documentView?.needsDisplay = true
previewView.updateLayer()
@H_673_20@但没有运气.我已尝试用代码滚动PDFView,但它不是一种可靠的方式来偷偷摸摸,并且通常不应该是这样做的方法.

大佬总结

以上是大佬教程为你收集整理的objective-c – PDFView setNeedsDisplay:YES在MacOS Sierra 10.12上不起作用全部内容,希望文章能够帮你解决objective-c – PDFView setNeedsDisplay:YES在MacOS Sierra 10.12上不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。