PDFView setNeedsDisplay:YES在MacOS Sierra 10.12上不起作用 [英] PDFView setNeedsDisplay:YES doesn't work on MacOS Sierra 10.12

查看:112
本文介绍了PDFView setNeedsDisplay:YES在MacOS Sierra 10.12上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用[PDFView setNeedsDisplay:YES]来重新绘制PDF视图,并且在OSX 10.9-10.11上效果很好. 但是,除非我放大或缩小PDF页面,否则它将无法正常工作.

I have use [PDFView setNeedsDisplay:YES] to let the PDF view redraw, and it worked great on OSX 10.9-10.11. However it doesn't work unless I zoom in or zoom out the PDF page...

还有其他方法可以立即重绘吗?下面的代码:

Is there any other way to redraw immediately? Code below:

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:

I found that the setNeedsDispaly calls the drawPage:toContext: however the drawing code doesn't work in 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画一条线.

the debug said CGContextSetFillColorWithColor: invalid context 0x0 and more invalid context 0x0 warnings. What I do in the drawPage:toContext: is testing and just use BezierPath to draw a line.

推荐答案

我遇到了同样的麻烦.第一次添加注释时,PDFView会立即在页面上显示该注释.从那时起,添加或删除批注在代码中就可以正常工作,但是PDFView在我手动滚动视图之前不会显示更改.

I'm having the same trouble. The first time I add an annotation, PDFView displays that annotation on the page immediately. From then on, adding or removing an annotation works fine in code but PDFView doesn't show the change until I manually scroll the view.

PDFKit中,我尝试过:

previewView.layoutDocumentView()

for pageIndex in 0...pdf.pageCount - 1 {
  let page = pdf.page(at: pageIndex)!
  previewView.annotationsChanged(on: page)
}

,并且从NSView开始,我尝试过:

and from NSView I've tried:

previewView.needsDisplay = true
previewView.needsLayout = true
previewView.documentView?.needsDisplay = true
previewView.updateLayer()

但是没有运气.我也尝试过用代码滚动PDFView,但是它不是偷偷摸摸的可靠方式,通常不应该这样做.

but no luck. I've tried scrolling the PDFView with code too but it hasn't been a reliable way of sneaking a refresh, and in general shouldn't be the way to do this.

这篇关于PDFView setNeedsDisplay:YES在MacOS Sierra 10.12上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆