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 8737519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:32:28+00:00 2026-06-13T10:32:28+00:00

I currently have the following code to try and allow the user to draw

  • 0

I currently have the following code to try and allow the user to draw a dotted path and make a custom shape. Once they have made this shape, I wanted it to automatically be filled with colour. That isn’t happening.

At the moment I am getting this error for the code below:

<Error>: CGContextClosePath: no current point.

Here’s the code I’m using:

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

UITouch *touch = [touches anyObject];

CGPoint previous = [touch previousLocationInView:self];
CGPoint current = [touch locationInView:self];

#define SQR(x) ((x)*(x))
//Check for a minimal distance to avoid silly data
if ((SQR(current.x - self.previousPoint2.x) + SQR(current.y - self.previousPoint2.y)) > SQR(10))
{

    float dashPhase = 5.0;
    float dashLengths[] = {10, 10};
    CGContextSetLineDash(context,
                         dashPhase, dashLengths, 2);

    CGContextSetFillColorWithColor(context, [[UIColor lightGrayColor] CGColor]);
    CGContextFillPath(context);

    CGContextSetLineWidth(context, 2);
    CGFloat gray[4] = {0.5f, 0.5f, 0.5f, 1.0f};
    CGContextSetStrokeColor(context, gray);

    self.brushSize = 5;
    self.brushColor = [UIColor lightGrayColor];

    self.previousPoint2 = self.previousPoint1;
    self.previousPoint1 = previous;
    self.currentPoint = current;

    // calculate mid point
    self.mid1 = [self pointBetween:self.previousPoint1 andPoint:self.previousPoint2];
    self.mid2 = [self pointBetween:self.currentPoint andPoint:self.previousPoint1];

    if(self.paths.count == 0)
    {

    UIBezierPath* newPath = [UIBezierPath bezierPath];

    CGContextBeginPath(context);

    [newPath moveToPoint:self.mid1];
    [newPath addLineToPoint:self.mid2];
    [self.paths addObject:newPath];

    CGContextClosePath(context);

    }

    else

    {

        UIBezierPath* lastPath = [self.paths lastObject];

        CGContextBeginPath(context);

        [lastPath addLineToPoint:self.mid2];
        [self.paths replaceObjectAtIndex:[self.paths indexOfObject:[self.paths lastObject]] withObject:lastPath];

        CGContextClosePath(context);

    }

    //Save
    [self.pathColors addObject:self.brushColor];

    self.needsToRedraw = YES;
  [self setNeedsDisplayInRect:[self dirtyRect]];
  //[self setNeedsDisplay];
}

}

Why is this happening and why is the inside of the path not being filled with colour?

  • 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-13T10:32:30+00:00Added an answer on June 13, 2026 at 10:32 am

    Your code has a few issues:

    • You should be doing your drawing in your view’s drawRect: method, not the touch handler.
    • You never set the variable context with a value for the current context. Do that with the UIGraphicsGetCurrentContext() method. Again, within your drawRect: method.
    • You go through the trouble of creating a UIBezierPath object, but you never use it. Do that by calling CGContextAddPath( context, newPath.CGPath ), changing the variable name as needed in the two places you appear to the using a UIBezierPath.
    • Keep the call to setNeedsDisplayInRect: in your touch handler method. That tells the system to do the work to update your view using the drawing that your (yet to be implemented) drawRect: method draws.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following code which delays showing a fixed bar after a
Currently I have the following code to flash a DataGrid cell when it's value
I currently have the following js code function clearMulti(option) { var i; var select
The following code shows what I currently have. It is an adapter for circular
I have the following code currently: <DataTemplate DataType={x:Type vm:SectionViewModel}> <ScrollViewer> <ItemsControl ItemsSource={Binding ViewModels}> </ItemsControl>
I am currently working on Problem 62 I have tried the following code to
I currently have code that does the following: private final static ExecutorService pool =
hi i have the following code below, where i try to get all the
I currently have the following code: public class Count { public static void countChar()
I currently have an alternative table row color with the following javascript code: function

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.