手势的识别

手势是可以通过代码或者在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.
        //获取用户默认的函数
        
       }
}
可以用手势来进行模拟

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

大笑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值