I have this code that retrieves the coordinates of an object when it is panned:
UITapGestureRecognizer *moveBuildingTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(moveobject:)];
Method moveobject contents:
CGPoint tapPoint=[recognizer locationOfTouch:0 inView:self.view];
I use this to change the frame of – move it -an imageview using these coordinates.
However, upon dragging the image around – triggering the uipangesturerecognizer action, I found that when I drag it to the absolute bottom, I get an error that -[UIPanGestureRecognizer locationOfTouch:inView:]: index (0) beyond bounds (0).
How can I solve this exception and prevent the user from dragging past this point?
Thanks
It’s weird that your
moveobject:method gets called even though the private touches array of the gesture recognizer seems to be empty.Anyway, in general, if you don’t handle multitouch gestures within gesture recognizer, I would suggest to use
[recognizer locationInView:]rather thenlocationOfTouch:inView:.Btw:
Your talking about a
UIPanGestureRecognizerwhile in the code you’re using aUITapGestureRecognizer.The code I would recommend to handle dragging of a particular view looks like this: