David Moe
David Moe

Reputation: 11

How to get the UIView object at the location of UITouch from - (void)touchesEnded:withEvent:?

I want to get the object at the location of where the touch is lifted (off the screen).

This will be used to implement a drag-and-drop and I have these methods for overriding:

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;

Using [[touches anyObject] view] in touchesEnded:withEvent: gives me the UIView object of where I first touched but not where I released my touch.

Using [[touches anyObject] locationInView:self.view] does give me the location of where the touch was released but I would have to map the coordinates to UIView.

Upvotes: 0

Views: 616

Answers (1)

David Moe
David Moe

Reputation: 11

The answer to this question was answered in a different question worded differently.

Answered by @Ronak Chaniyara: https://stackoverflow.com/a/16329436/3920809

Upvotes: 0

Related Questions