博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍
阅读量:4600 次
发布时间:2019-06-09

本文共 2527 字,大约阅读时间需要 8 分钟。

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}

 

转载于:https://www.cnblogs.com/Free-Thinker/p/5329287.html

你可能感兴趣的文章
前端开发在线小工具
查看>>
有关cookies使用方法
查看>>
Hadoop 使用Combiner提高Map/Reduce程序效率
查看>>
前言 转录组
查看>>
扫描图片怎么转换成文字
查看>>
easyui刷新渲染
查看>>
kindeditor 引用js架包问题
查看>>
POJ 1743 Musical Theme (后缀数组,求最长不重叠重复子串)(转)
查看>>
js中的delete
查看>>
centos 安装jenkins
查看>>
PAT 1054. 求平均值 (20)
查看>>
AX 2009 List类和Array类
查看>>
iOS阶段学习第13天笔记(多态)
查看>>
第三次作业
查看>>
第一章:计算机漫游1.1:信息就是位+上下文
查看>>
模二运算(转)(CRC檢驗)
查看>>
第六节
查看>>
使用Maven构建多模块企业项目
查看>>
约瑟夫问题
查看>>
python变量传递给系统命令的方法
查看>>