I currently have a UIImageView which I can move/drag around the view.
How does on detect for the edge of the screen when the image moves and stop the image from being able to be moved out of the screens view?
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.
You can find the rectangle of the
UIImageViewin the coordinates of your (outermost) view usingThen it’s a matter of checking if
rgoes out of bounds, e.g. like this:Of course, this should be put in your dragging code, with the
NSLog()statements replaced with appropriate handling (e.g. by only updating location in the last case, or by translating the rect back into view if needed)