简体   繁体   中英

How do I create an action after a specific number of touches on a screen?

I am making an app that has to save the screen, like a screenshot, when the screen is tapped or touched a specific number of times. I have tried all of the solutions that other users have suggested that are associated with my question, but nothing helps...

I will appreciate all suggestions. :) Thanks

The following blog post does a good job of explaining the built-in option for recognizing multiple taps in a row (and explains the shortcomings): Detecting tap and double-tap with Gesture Recognizers .

If you need more customized logic than is provided by the built-in gesture recognizers, you will either be implementing your own custom subclass of UIGestureRecognizer or you will be adding your logic into the UIResponder (superclass of UIViewController , UIView , etc.) callbacks for tap input: touchesBegan:withEvent: , touchesMoved:withEvent: , and touchesEnded:withEvent: .

I have more experience with the latter method (not UIGestureRecognizer ). The UITouch events passed to the various UIResponder callbacks each contain information about touch location and touch timing. You could use this information in combination with a NSTimer to determine if the user taps twice (or more) within a certain amount of time. If the timer fires before the second (or n th touch), then you can consider it a single touch event.

I don't know if that is the best way to do this, but it is certainly more granular control than the built-in UIGestureRecognizer s provide you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM