Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlighting the PDF - iOS
    text
    copied!<p>I want to implement a Highlight function in my pdf reader app. Unfortunately, my research yielded very few information about this. However, I came to believe that I will have to use an "overlay" where the drawing or "highlighting" must be done. What I plan to do now is add a CALayer into the pdf. I am successful in rendering shapes into the layer (e.g a simple line, circle, and a square), but I can't seem to draw freely into it (like in Draw Something). Here is the code I used:</p> <p>When the user begins highlighting:</p> <pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; prevPoint = [touch locationInView:theContentView]; drawImageLayer = [CALayer layer]; drawImageLayer.frame = theContentView.frame; [theContentView.layer addSublayer:drawImageLayer]; } </code></pre> <p>When the user is starting the highlighting:</p> <pre><code>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; currPoint = [touch locationInView:theContentView]; drawImageLayer.delegate = self; [drawImageLayer setNeedsDisplay]; } </code></pre> <p>This is the code where the drawing happens:</p> <pre><code>- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{ NSLog(@"DrawLayer being called.."); CGContextSaveGState(ctx); CGContextSetLineCap(ctx, kCGLineCapRound); CGContextSetLineWidth(ctx, 1.0); CGContextSetRGBStrokeColor(ctx, 1, 0, 0, 1); CGContextBeginPath(ctx); CGContextMoveToPoint(ctx, prevPoint.x, prevPoint.y); CGContextAddLineToPoint(ctx, currPoint.x, currPoint.y); CGContextStrokePath(ctx); prevPoint = currPoint; CGContextRestoreGState(ctx); } </code></pre> <p>What happens is that it draws a point and that point follows the cursor everywhere! Can anyone tell me what's wrong with this code?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload