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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:25:51+00:00 2026-05-31T11:25:51+00:00

Background: I am trying to create a really simple iPhone app that will allow

  • 0

Background: I am trying to create a really simple iPhone app that will allow the user to draw multiple straight lines on the screen with their finger.

I’m using these two methods in my UIViewController to capture the coordinates of each line’s endpoints.

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

Question:
I would like the line to show up as soon as touchesEnded has fired and then keep drawing more lines on the screen. How do I do this? I don’t necessarily need the code, but I need help with the big picture idea of how to put it together. Also, I’m not a huge fan of xibs and like to do things all programmatically if that affects the answer.

What I’ve Tried: I’ve tried using Quartz 2d but it seems in order to use that, you have to do your drawing in the drawRect method of a separate subclassed view. So I would have to create a new view for each line? and then my coordinates would be messed up b/c I’d have to translate the touches positions from the UIViewController to the view.

I’ve also tried with OpenGL, which I’ve had a bit more success with (using the GLPaint sample as a template) but OpenGL seems like overkill for just drawing some straight lines on the screen.

  • 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-31T11:25:53+00:00Added an answer on May 31, 2026 at 11:25 am

    You don’t need multiple views, and you don’t need OpenGL.

    Make a subclass of UIView — call it CanvasView.

    Make an object to represent “a line” in your canvas — it would be a subclass of NSObject with CGPoint properties for start and end.

    CanvasView should keep an array of the lines that are in the canvas.

    In -[CanvasView drawRect:], loop through the lines in the array, and draw each one.

    In -[CanvasView touchesBegan:withEvent:], stash the start point in an instance variable.
    In -[CanvasView touchesEnded:withEvent:], make a new line with the start and end points, and add it to your array of lines. Call [self setNeedsDisplay] to cause the view to be redrawn.

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

Sidebar

Related Questions

Background: I'm trying to create a pure D language implementation of functionality that's roughly
What i'm trying to create is a background worker that executes a few processes
A little background: I'm using Spring and Hibernate to create a really simple domain/dao/service
I'm trying to create a page that allows a user to change the "look
I'm trying to develop a really simple app in xcode 4. It's a utility
Background I am trying to create a copy of a business object I have
Trying to create a background-image slideshow and am getting this error... This is the
I am trying to create a table with an image as a background. To
Greetings, coders, Background Info and Code I am trying to create a daemon-type program
Background: I'm trying to come up with a regex for a rewrite rule that

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.