touchesEnded not being called??? or randomly being called
Asked Answered
C

7

8

If I lift my finger up off the first touch, then it will recognize the next touch just fine. It's only when I hold my first touch down continuously and then try and touch a different area with a different finger at the same time. It will then incorrectly register that second touch as being from the first touch again.

Update It has something to do with touchesEnded not being called until the very LAST touch has ended (it doesn't care if you already had 5 other touches end before you finally let go of the last one... it calls them all to end once the very last touch ends)

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

 UITouch* touch = [touches anyObject];

 NSString* filename = [listOfStuff objectAtIndex:[touch view].tag];

// do something with the filename now

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

 ITouch* touch = [touches anyObject];
 NSString* buttonPressed = [listOfStuff objectAtIndex:[touch view].tag];

 // do something with this info now
}
Clarhe answered 28/4, 2010 at 2:51 Comment(4)
I created a simple test project and it seems that touchesEnded gets called each time any finger is lifted...Coarse
Vladimir, would you mind posting your code example somewhere so I can see what differs? For whatever reason, all of my touchesEnded are getting called later on all at the same time instead of when they actually happenClarhe
By the way, in my program the touches are on UIImageViews that are within a scrollview and all of that is within a UIView if that makes any differenceClarhe
Vladimir, Could it have something to do with all the UIImageViews being within a scrollview? Outside of the scrollview they do fine and send the touchesEnded message immediately, but within the scrollview they don't send the message immediately. Does this get delayed somehow or is it not being sent up the responder chain correctly?Clarhe
C
7

For whatever reason, touchesEnded is being delayed only when the touch is within the scrollview. If you either a) disable the scrollview from scrolling; or b) don't use a scrollview, then touchesEnded gets delivered right away.

I have heard where some people have intercepted sendEvent, but that seems sketchy to me and I really don't want to screw up the responder chain since sendEvent handles an awful lot of events.

Any additional thoughts? Has anyone ever subclassed UIWindow to try and intercept the touches that way? Any input you could provide is appreciated.

Clarhe answered 4/5, 2010 at 2:35 Comment(0)
R
10

I had this today, (or rather I had this problem dumped on me today!).

What I saw happening:

  • Touch Screen With Finger 1
  • touchesBegan fires
  • Touch Screen With Finger 2
  • touchesBegan fires
  • Release Finger 2
  • nothing happens
  • Release Finger 1
  • touchesEnded fires
  • touchesEnded fires

As Gavin Clifton said, it only happens if you add a gesture recognizer. Without a recognizer added, touchesEnded fires after each finger is released. Which would be great if I didn't need to use recognizers...!!!

I solved this by adding gestureRotation.delaysTouchesEnded = FALSE; to my recognizer creation/adding code:

gestureRotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRotation_Callback:)];

[gestureRotation setDelegate:self];
gestureRotation.cancelsTouchesInView = FALSE;
gestureRotation.delaysTouchesEnded = FALSE;        // <---- this line!!
[self.view addGestureRecognizer: gestureRotation];
[gestureRotation release];

Now the gestures work, and touchesBegan no longer queues!

Ramp answered 13/7, 2012 at 10:1 Comment(0)
C
7

For whatever reason, touchesEnded is being delayed only when the touch is within the scrollview. If you either a) disable the scrollview from scrolling; or b) don't use a scrollview, then touchesEnded gets delivered right away.

I have heard where some people have intercepted sendEvent, but that seems sketchy to me and I really don't want to screw up the responder chain since sendEvent handles an awful lot of events.

Any additional thoughts? Has anyone ever subclassed UIWindow to try and intercept the touches that way? Any input you could provide is appreciated.

Clarhe answered 4/5, 2010 at 2:35 Comment(0)
M
6

The scrollview has a property delaysContentTouches which is set to YES by default. It will delay all touch events until it determines a scrolling gesture.

Maldives answered 9/10, 2011 at 22:54 Comment(0)
S
5

I know this question is a bit old but I thought I'd share my experience for anyone who stumbles across this thread looking for an answer, like I just have.

I've been struggling with this problem for a few hours and the only solution I could come up with was to remove any UIGestureRecognizer objects that I was using.

For my setup I was using pan and tap recognizers to capture those gestures, and using touchesBegan and touchesEnded for any standard touch events. It wasn't until I removed the UIGestureRecognizer objects that the touchesEnded method started getting called again for the second touch ending. Specifically it was the pan recognizer that was causing the issues.

I'm not totally sure if this applies in this case but it solved the issues I was having.

Sleeve answered 21/6, 2012 at 19:34 Comment(0)
Q
0

Set multipleTouchEnabled.

In Interface Builder, it's the "Multiple Touch" checkbox under "User Interaction Enabled."

Qadi answered 28/4, 2010 at 2:57 Comment(2)
tewha, you may be onto the right track here... I am creating the UIImageViews in code and setting MultipleTouchEnabled during that setup. For some reason, I'm not sure it's getting set properly. I have read elsewhere that if MultipleTouchEnabled is not set to YES, then touchesEnded will not get called until the very last touch has ended (which matches my error exactly!).Clarhe
Nevermind, just checked that all were enabled and sure enough multipleTouchEnabled is YES for all :( Could it have something to do with all the UIImageViews being within a scrollview? Outside of the scrollview they do fine, but within the scrollview they don't send the message immediately.Clarhe
S
0

I just had this problem, where a touchesEnded would never be called on a button within a ScrollView. Based on Ovidiu's answer, I discovered that manually setting the ContentOffset of my ScrollView was causing the problem. Presumably having the contentOffset set the way I had it was confusing the ScrollView as to whether I was trying to press the button or scroll the view.

Letting the offset stay at 0,0 made the problem go away.

Snippet answered 24/7, 2015 at 23:59 Comment(0)
G
0

I found another option.

After touchesBegan and CGPoint not moved according to touchesMoved, touchesCancelled called.

However, If CGPoint changed according to touchesMoved, touchesEnded called.

Gan answered 12/2, 2018 at 6:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.