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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:56:19+00:00 2026-05-12T19:56:19+00:00

I am trying to make an application for drawing shapes on screen by touching

  • 0

I am trying to make an application for drawing shapes on screen by touching it.

I can draw a line from one point to another- but it erases on each new draw.

Here is my code:

CGPoint location;
CGContextRef context;
CGPoint drawAtPoint;
CGPoint lastPoint;
-(void)awakeFromNib{
    //[self addSubview:noteView];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    location = [touch locationInView:touch.view];
    [self setNeedsDisplayInRect:CGRectMake(0, 0, 320, 480)];
}

- (void)drawRect:(CGRect)rect {
    context = UIGraphicsGetCurrentContext();
    [[UIColor blueColor] set];
    CGContextSetLineWidth(context,10);
    drawAtPoint.x =location.x;
    drawAtPoint.y =location.y;
    CGContextAddEllipseInRect(context,CGRectMake(drawAtPoint.x, drawAtPoint.y, 2, 2));
    CGContextAddLineToPoint(context,lastPoint.x, lastPoint.y);
    CGContextStrokePath(context);

    lastPoint.x =location.x;
    lastPoint.y =location.y;
}

Appreciate your help-

Nir.

  • 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-05-12T19:56:19+00:00Added an answer on May 12, 2026 at 7:56 pm

    As you have discovered, -drawRect is where you display the contents of a view. You will only ‘see’ on screen what you draw here.

    This is much more low-level than something like Flash where you might add a movieclip containing a line to the stage and some time later add another movieclip containing a line to the stage and now you see – two lines!

    You will need to do some work and prdobably set up something like..

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    
        UITouch *touch = [[event allTouches] anyObject]; 
        location = [touch locationInView:touch.view]; 
    
        [self addNewLineFrom:lastPoint to:location];
    
        lastPoint = location;
    
        [self setNeedsDisplayInRect:CGRectMake(0, 0, 320, 480)]; 
    }
    
    - (void)drawRect:(CGRect)rect {
    
        context = UIGraphicsGetCurrentContext();
    
        for( Line *eachLine in lineArray )
            [eachLine drawInContext:context];
    
    }
    

    I think you can see how to flesh this out to what you need.

    Another way to approach this is to use CALayers. Using this approach you dont draw inside – – (void)drawRect at all – you add and remove layers, draw what you like inside them, and the view will handle compositing them together and drawing to the screen as needed. Probably more what you are looking for.

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

Sidebar

Related Questions

I am trying to make an application which can connect from a mobile to
I'm trying to make some drawing application and I get strange results in my
I'm trying to make a vector drawing application using OpenGL which will allow the
I am trying to make a simple application which will be used to point
I am trying to make a application where a dialog will come from where
I am trying to make an application, which reads the data from a serial
I'm trying to make my application sleep the screen. I've looked into pmset with
I'm trying to make an application that keeps an object model in sync with
Alright so here is the deal. I am trying to make a application that's
Recently I was trying to make a calendar application that will display the current

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.