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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:47:24+00:00 2026-05-12T18:47:24+00:00

Still an iphone dev starter but trying. I would like to have the user

  • 0

Still an iphone dev starter but trying.

I would like to have the user touch the screen at which point a pin (dot) will be placed on the view.

I have accomplished this (yey) but i would like to have snap to grip effect, and can not come up with a solution.
This is how i am placing that dot:

CGPoint drawPoint = CGPointMake(lastTouch.x – horizontalOffset, lastTouch.y – >verticalOffset);
[drawImage drawAtPoint:drawPoint]; //Tell the image to draw itself

I have a grid as a background on a Viewcontroller, overlapping that grid i have a UIView with custom drawing that displays a pin every time the user touches the screen.

(and for some reason the dot already appears before the user touches… all though that is another query that i am looking into at the moment)

So snap to grid effect. Any ideas?

  • 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-12T18:47:24+00:00Added an answer on May 12, 2026 at 6:47 pm

    Assuming that your approach is to let the user tap, and then put the pin at the closest grid intersection, this is basically just a rounding problem.

    // assume these constants
    // kVGridOffset, kHGridOffset: the difference between the origin of the view
    //   and the origin of the grid
    // kVGridSpacing, kHGridSpacing: the size of the grid itself
    
    // set initial coordinates from touch
    CGPoint drawPoint = CGPointMake(lastTouch.x - horizontalOffset, lastTouch.y - verticalOffset);
    
    // remove the offset, round to nearest increment of spacing, and return offset
    drawPoint.x = floor((drawPoint.x - kHGridOffset) / kHGridSpacing + 0.5) * kHGridSpacing + kHGridOffset;
    drawPoint.y = floor((drawPoint.y - kVGridOffset) / kVGridSpacing + 0.5) * kVGridSpacing + kVGridOffset;
    
    // draw the image
    [drawImage drawAtPoint:drawPoint];
    

    EDIT: with the availability of nearbyint() for rounding, things can be a little neater:

    drawPoint.x = nearbyint((drawPoint.x - kHGridOffset) / kHGridSpacing) * kHGridSpacing + kHGridOffset;
    drawPoint.y = nearbyint((drawPoint.y - kVGridOffset) / kVGridSpacing) * kVGridSpacing + kVGridOffset;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $myShippingModel = Mage::getSingleton('shipping/api'); // The name here is based on… May 13, 2026 at 9:53 am
  • Editorial Team
    Editorial Team added an answer Right click the project, go to properties, and make sure… May 13, 2026 at 9:53 am
  • Editorial Team
    Editorial Team added an answer In C#, you cannot create a constant that is retrieved… May 13, 2026 at 9:53 am

Related Questions

I've got a few apps under my belt now, but I'm still relatively new
I'm using the PageControl project, which is on Apple's dev site. I've added a
I am relatively new to Xcode and one thing that has bothered me is
If I create an application on my Mac, is there any way I can

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.