PDFView setNeedsDisplay: YES not working on MacOS Sierra 10.12

I use [PDFView setNeedsDisplay:YES]to redraw the PDF view, and it worked fine on OSX 10.9-10.11. However, this does not work if I do not enlarge or reduce the PDF page ...

Is there any other way to redraw right away? 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;

UPDATE

I found that setNeedsDispalycauses drawPage:toContext:, however the drawing code does not work indrawPage: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];
}

Debugging reported CGContextSetFillColorWithColor: invalid context 0x0and more invalid context 0x0warnings. What I'm doing at drawPage:toContext:is testing, and just use BezierPath to draw a string.

+4
source share
1 answer

. , , 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 , , .

0

Source: https://habr.com/ru/post/1656769/


All Articles