Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:12:52+00:00 2026-06-05T13:12:52+00:00

I want to implement a Highlight function in my pdf reader app. Unfortunately, my

  • 0

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:

When the user begins highlighting:

- (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];

}

When the user is starting the highlighting:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
    currPoint = [touch locationInView:theContentView];
    drawImageLayer.delegate = self;

    [drawImageLayer setNeedsDisplay];
}

This is the code where the drawing happens:

- (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);

}

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:12:53+00:00Added an answer on June 5, 2026 at 1:12 pm

    drawLayer: redraws the entire layer; it does not keep what was previously drawn. You draw a line from prevPoint to currPoint then update currPoint. Since drawLayer: will be called whenever you update currPoint (since you call setNeedsDisplay), prevPoint will be very close to currPoint, which is why you basically just see a point following the user’s finger.

    If you want a straight line starting where the user touched down and ending where the user’s finger currently is, you probably want to just get rid of the line
    prevPoint = currPoint;, which will thus always draw a line from where the user first touched down to where the users’ finger currently is.

    If you want a smooth line that follows the user’s finger, then you’ll need to keep track of a list of points, and connect all of them together in drawLayer. In practice, since touchesMoved: is not called after every single-pixel move, you might have to interpolate a curve that smoothly connects all the points.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I want to implement basic shopping cart functionality in my Rails app....are there any
In My app i have implement the ListView . Now i want it to
everyone! My english is poor and sorry fot that. I want implement a function
I'm trying to implement an autocomplete field. I want this autocomplete to retrieve the
I want to implement a firebug like highlight when my cursor hovers an element
I would like to implement similar to iCal implementation. I want to highlight and
I want implement drag text between textfield like mail app of ios5. here is
I want implement in my software solution an VBA editor but in c# 3.0.
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.