How can I drag an image or button, then when the image is on a specific spot, i.e. (x = 240 y = 240) it will stay there?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
I’ll assume iOS as I’m more familiar with it than with OS X.
To make a view draggable, detect a touch dragging it using the following three methods:
The trick is that you should store the touch’s location in the view’s superview, then in the 2nd method, update the position of the view itself accordingly. When you detect that the view’s center or origin reached a certain point (don’t check it using ==, it doesn’t work well for floating-point numbers, use some small epsilon to detect whether the view is inside a desired area), you can set a boolean flag on the view, then check that boolean flag in the touchesMoved method and not update the view’s location anymore.