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

  • Home
  • SEARCH
  • 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 8002315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:19:29+00:00 2026-06-04T16:19:29+00:00

I am making a math related activity in which the user can draw with

  • 0

I am making a math related activity in which the user can draw with their fingers for scratch work as they try to solve the math question. However, I notice that when I move my finger quickly, the line lags behind my finger somewhat noticeably. I was wondering if there was some area I had overlooked for performance or if touchesMoved simply just doesn’t come enough (it is perfectly smooth and wonderful if you don’t move fast). I am using UIBezierPath. First I create it in my init method like this:

myPath=[[UIBezierPath alloc]init];
myPath.lineCapStyle=kCGLineCapSquare;
myPath.lineJoinStyle = kCGLineJoinBevel;
myPath.lineWidth=5;
myPath.flatness = 0.4;

Then in drawRect:

- (void)drawRect:(CGRect)rect
{
    [brushPattern setStroke];
    if(baseImageView.image)
    {
        CGContextRef c = UIGraphicsGetCurrentContext();
        [baseImageView.layer renderInContext:c];
    }

    CGBlendMode blendMode = self.erase ? kCGBlendModeClear : kCGBlendModeNormal;
    [myPath strokeWithBlendMode:blendMode alpha:1.0];
}

baseImageView is what I use to save the result so that I don’t have to draw many paths (gets really slow after a while). Here is my touch logic:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath moveToPoint:[mytouch locationInView:self]];

}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{    
    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath addLineToPoint:[mytouch locationInView:self]];
    [self setNeedsDisplay];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{    
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0f);
    CGContextRef c = UIGraphicsGetCurrentContext();
    [self.layer renderInContext:c];

    baseImageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [myPath removeAllPoints];
    [self setNeedsDisplay];
}

This project is going to be released as an enterprise app, so it will only be installed on iPad 2. Target iOS is 5.0. Any suggestions about how I can squeeze a little more speed out of this would be appreciated.

  • 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-04T16:19:31+00:00Added an answer on June 4, 2026 at 4:19 pm

    Of course you should start by running it under Instruments and look for your hotspots. Then you need to to make changes and re-evaluate to see their impact. Otherwise you’re just guessing. That said, some notes from experience:

    • Adding lots of elements to a path can get very expensive. I would not be surprised if your addLineToPoint: turns out to be a hotspot. It has been for me.
    • Rather than backing your system with a UIImageView, I would probably render into a CGLayer. CGLayers are optimized for rendering into a specific context.
    • Why accumulate the path at all rather than just rendering it into the layer at each step? That way your path would never be more than two elements (move, addLine). Typically the two-stage approach is used so you can handle undo or the like.
    • Make sure that you’re turning off any UIBezierPath features you don’t want. In particular, look at the section “Accessing Draw Properties” in the docs. You may consider switching to CGMutablePath rather than UIBezierPath. It’s not actually faster when configured the same, but it’s default settings turn more things off, so by default it’s faster. (You’re already setting most of these; you’ll want to experiment a little in Instruments to see what impact they make.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making programs that solve and show work for math problems. I would
Making a simple application, so when the user logs out of Windows, it of
Making an adobe flex ui in which data that is calculated must use proprietary
Im making a collision checking system with jQuery however it doesn't seem to work.
I'm making an application that gives clients and approximate loan offer (they are later
I'm making a small program for math (no particular reason, just kind of wanted
I am making a program where one can click on the window, and a
I'm making a program in Java with Sockets. I can send commands to the
Related: what can I use as std::map keys? I needed to create a mapping
So I am making a script that adds two numbers (decimal numbers) together, which

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.