关闭

手势的识别

166人阅读 评论(0) 收藏 举报
分类:

手势是可以通过代码或者在xib中直接拖进来来生成的


下面介绍动态使用代码来创建手势

import UIKit

class ViewController: UIViewController {

       
    override func viewDidLoad() {
        //点击事件
        var atep = UITapGestureRecognizer(target: self, action: "tapDo:")
        self.view.addGestureRecognizer(atep)
        //单击的次数
        atep.numberOfTapsRequired = 1
        //拖动的事件
        var aPan = UIPanGestureRecognizer(target: self, action: "handlenPan:")
        self.view.addGestureRecognizer(aPan)
        //最少手指的个数
        aPan.minimumNumberOfTouches = 1
        //最多的手指的个数
        aPan.maximumNumberOfTouches = 3
        //长按的事件
        var aLongPress = UILongPressGestureRecognizer(target: self, action: "longPress:")
        self.view.addGestureRecognizer(aLongPress)
        //需要长按的时间 至少 0.5
        aLongPress.minimumPressDuration = 0.5
        //粘合事件
        var aPinch =  UIPinchGestureRecognizer(target: self, action: "pinchDo:")
        self.view.addGestureRecognizer(aPinch)
        //旋转的事件
        
        var aRotation = UIRotationGestureRecognizer(target: self, action: "rotationPiece:")
        self.view.addGestureRecognizer(aRotation)
        //清扫的事件 左清扫
        var leftSwipe = UISwipeGestureRecognizer(target: self, action: "leftSwipe:")
        self.view.addGestureRecognizer(leftSwipe)
        leftSwipe.direction = UISwipeGestureRecognizerDirection.Left
        //左右上下的清扫都一样
        
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
    }
    //实现事件
    func tapDo(sender:UITapGestureRecognizer) {
        print("点击事件")
    }
       override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        //获取用户默认的函数
        
       }
}
可以用手势来进行模拟

还有很多信息 具体可以看文档

大笑

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:67003次
    • 积分:2554
    • 等级:
    • 排名:第14443名
    • 原创:197篇
    • 转载:0篇
    • 译文:0篇
    • 评论:5条
    最新评论