What is the best way to create a custom “tickle” UIGestureRecognizer?

心不动则不痛 提交于 2019-12-01 06:58:30

问题


I would like to create a custom UIGestureRecognizer for a "tickle"... in other words, detecting a swipeLeft followed by a swipeRight, twice, without lifting the finger.

I know I can create it by starting from scratch with a custom gesture, but then I'll need to implement all the 'touches' methods and basically re-invent the swipe gestures. Is there any way of creating a custom UIGestureRecognizer just by combining ones that already exist? In other words, a custom UIGestureRecognizer that extends a UISwipeGestureRecognizer?

Or will I need to build it from scratch? If so, does anyone know the underlying code for a swipe gesture?


回答1:


I know you hesitate to build it from scratch, but tbh, any other way would feel "hacked together".

Besides, building this particular gesture from scratch will be easy because Ray Wenderlich's gesture recognizer tutorial actual talks about implementing your own custom gesture... Now only that, but he shows you how to implement a tickle gesture!

Here's a link to his tutorial: http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more

The part about the tickle gesture is towards the bottom. Feel free to follow his tutorial and learn how to use it, or you can probably just download his sample code and copy/paste his tickle gesture recognizer class.

Edit: Oops, this question is many months old. Oh well, it has an answer now.



来源:https://stackoverflow.com/questions/7891625/what-is-the-best-way-to-create-a-custom-tickle-uigesturerecognizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!