如何使用iOS手势UIGestureRecognizer
1个回答
2016-07-08 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
UIGestureRecognizer是iOS手势基类
主要我们使用下列子类进行开发:
//Tap(点击)
1、UITapGestureRecognizer
//Pinch(捏合)
2、UIPinchGestureRecognizer
//Rotation(旋转)
3、UIRotationGestureRecognizer
//Swipe(滑动,快速移动,是用于监测滑动的方向的)
4、UISwipeGestureRecognizer
//Pan (拖移,慢速移动,是用于监测偏移的量的)
5、UIPanGestureRecognizer
//LongPress(长按)
6、UILongPressGestureRecognizer
给你举个详细的例子:
//<1>单击
UITapGestureRecognizer * single = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleAction:)];
//手指数
single.numberOfTouchesRequired = 1;
single.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:single];
//<2>双击
UITapGestureRecognizer * doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTapAction:)];
doubleTap.numberOfTouchesRequired = 1;
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
//<3>三击
UITapGestureRecognizer * third = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(thirdAction:)];
third.numberOfTapsRequired = 3;
third.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:third];
//为了避免干扰需要设置手势的优先级
[single requireGestureRecognizerToFail:doubleTap];
[doubleTap requireGestureRecognizerToFail:third];
主要我们使用下列子类进行开发:
//Tap(点击)
1、UITapGestureRecognizer
//Pinch(捏合)
2、UIPinchGestureRecognizer
//Rotation(旋转)
3、UIRotationGestureRecognizer
//Swipe(滑动,快速移动,是用于监测滑动的方向的)
4、UISwipeGestureRecognizer
//Pan (拖移,慢速移动,是用于监测偏移的量的)
5、UIPanGestureRecognizer
//LongPress(长按)
6、UILongPressGestureRecognizer
给你举个详细的例子:
//<1>单击
UITapGestureRecognizer * single = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleAction:)];
//手指数
single.numberOfTouchesRequired = 1;
single.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:single];
//<2>双击
UITapGestureRecognizer * doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTapAction:)];
doubleTap.numberOfTouchesRequired = 1;
doubleTap.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:doubleTap];
//<3>三击
UITapGestureRecognizer * third = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(thirdAction:)];
third.numberOfTapsRequired = 3;
third.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:third];
//为了避免干扰需要设置手势的优先级
[single requireGestureRecognizerToFail:doubleTap];
[doubleTap requireGestureRecognizerToFail:third];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询