Note: This is a question similar to what is asked here, but the answer provided there is not exactly a solution in my case. The question's objective is different too. Reference: touchesBegan - Only needs the last touch action - iPhone
I am trying to handle multiple touches in a UIView. I need to get the exact touch positions in order.
Currently, I am attaching a selector like this:
[myView addTarget:self action:@selector(touchBegan:withEvent:) forControlEvents: UIControlEventTouchDown];
This is my handler,
- (void)touchBegan:(UIButton *)c withEvent:ev {
UITouch *touch = [[ev allTouches] anyObject];
The problem here is that [ev allTouches] returns an NSSet that is unordered, so I am unable to get the exact last location of the touch event in case of multiple touches.
Is there a way I can get the last location in the case when multiple touches are handled?
You can always create a subclass of your View and override
hitTestto get the exact touch pointHere am just logging touch point. Just to show how it works with I have added
touchesBeganin my ViewController and logged first touch point from touches setHere is the console log for both
So hit test says, your touch point is (175.66667175293, 175.33332824707) while
touches.firstsays location in view : {175.66665649414062, 175.33332824707031} which are basically same.Can
hitTestbe used as replacement totouchBegan? No.Thats why I had asked in comments above what exactly are you trying to achieve. If you are looking for continuous monitoring of touches than
touchBegan,touchMove,touchEndare the delegates you should opt for, but if you are trying to monitor a single touch and find its exact touch point you can always make use ofhitTestHope it helps