Request the current number of touches on the screen without using events on the iPhone

I have an application that starts playing sound when the user touches the uiview and changes to different tones when the user slides a finger across the screen. The sound stops when the user lifts a finger.

I use touchsBegan, Moved, and Ended for this event.

My problem affects Ended (and / or canceled) sometimes it doesn’t work properly and the sound continues to play even after the finger is lifted from the screen.

So, as a workaround, I would like to implement a timer that will check the number of touches on the screen, and if it is zero, it will check and stop the audio player when playing.

I was looking for some code that could get me the number of touches like

UITouch * touches = [self getAllTouchesonScreen];

or something:)

+4
source share
3 answers

The event is sometimes not triggered.

I tried to set breakpoints for canceled touches and touched completed events and it sometimes misses.

try the GLPaint sample program from the Apple website and try NSLog's legs to finish and do some quick drawings on the screen and quickly lift your finger, for example, push your finger from the screen.

You will understand what I mean. My current solution for this includes an accelerometer :)

Hint: I use this to find all events: (void) event sendEvent: (UIEvent *)

+3
source
NSSet *allTouches = [event allTouches]; for(GLuint index = 0; index < [allTouches count]; ++index) { UITouch *touch = [[allTouches allObjects] objectAtIndex:index]; if([touch phase] != UITouchPhaseCancelled) { CGPoint touchPoint = [touch locationInView:self]; //do something with touchPoint that has state [touch phase] } } 

You can use this code in all touch event functions (touchsBegan, touchesEnded, touchesMoved), and you can count strokes and know their states.

+3
source

Do not forget about the touches. Add this function / method and NSLog when the touch ends there, I think you will find some missing touches.

If you are looking for a tap count - by clicking the same place more than once without moving your finger, you can get it through:

 -(void)iPhoneTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchPosition = [touch locationInView:self]; lastTouchTime = [touch timestamp]; myTouchCount = [touch tapCount]; 

But I also do this manually, using touchhesMoved, to see how the FAR has moved and canceled the double / triple push if any of the cranes has moved too far, and counting the cranes while you are in the actual state of the crane.

+1
source

Source: https://habr.com/ru/post/1307264/


All Articles