gpt4 book ai didi

Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 27 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

1.UITapGestureRecognizer 点击/双击手势 。

复制代码 代码如下:

var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:") 
//设置手势点击数,双击:点2下 
tapGesture.numberOfTapsRequired = 2 
self.view.addGestureRecognizer(tapGesture)

2.UIPinchGestureRecognizer 捏 (放大/缩小)手势 。

复制代码 代码如下:

var pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:") 
self.view.addGestureRecognizer(pinchGesture)

3.UIRotationGestureRecognizer 旋转手势 。

复制代码 代码如下:

var rotateGesture = UIRotationGestureRecognizer(target: self, action: "handleRotateGesture:") 
 self.view.addGestureRecognizer(rotateGesture) 

4. UIPanGestureRecognizer 拖动手势 。

复制代码 代码如下:

 var panGesture = UIPanGestureRecognizer(target: self, action: "handlePanGesture:") 
 self.view.addGestureRecognizer(panGesture) 

5. UISwipeGestureRecognizer 划动手势 。

复制代码 代码如下:

var swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:") 
swipeGesture.direction = UISwipeGestureRecognizerDirection.Left //不设置是右 
self.view.addGestureRecognizer(swipeGesture)

6. UILongPressGestureRecognizer 长按手势 。

复制代码 代码如下:

   var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:")      //长按时间      // longpressGesutre.minimumPressDuration     //所需触摸次数     /// longpressGesutre.numberOfTouchesRequired      self.view.addGestureRecognizer(longpressGesutre)  UIGestureRecognizerState 枚举定义如下 。

  。

enum UIGestureRecognizerState : Int { 。

    case Possible // the recognizer has not yet recognized its gesture, but may be evaluating touch events. this is the default state 。

    case Began // the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop     case Changed // the recognizer has received touches recognized as a change to the gesture. the action method will be called at the next turn of the run loop     case Ended // the recognizer has received touches recognized as the end of the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible     case Cancelled // the recognizer has received touches resulting in the cancellation of the gesture. the action method will be called at the next turn of the run loop. the recognizer will be reset to UIGestureRecognizerStatePossible 。

    case Failed // the recognizer has received a touch sequence that can not be recognized as the gesture. the action method will not be called and the recognizer will be reset to UIGestureRecognizerStatePossible } 。

  。

最后此篇关于Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍的文章就讲到这里了,如果你想了解更多关于Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com