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

Ask A Question

Stats

  • Questions 208k
  • Answers 208k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I had exactly the same question and asked one of… May 12, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer Use a profiler. There's no way for us to know… May 12, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer [2nd answer, on semantics] This particular example happens to be… May 12, 2026 at 9:32 pm

Related Questions

I am working on a demo application for a library me and two colleagues
I am trying to make an application in which one component captures the screen
I am trying to implement an application for a friend who sells t-shirts and
Duplicate of: Learning to write a compiler Documentation on creating a programming language Learning
I am trying to make my application more customizable by allowing users to pick

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.