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;
currentBounds = [_activeAnnotation bounds];
mouseLoc = [self convertPoint: [theEvent locationInWindow] fromView: NULL];
if(activePage == nil)
activePage =[_activeAnnotation page];
_LinePoint= [self convertPoint: mouseLoc toPage: activePage];
endPt = [self convertPoint: mouseLoc toPage: activePage];
if(_selectedIdx == 3)
{
[(PDFAnnotationInk*)_activeAnnotation removeBezierPath:_path];
[_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.
source
share