IOS触屏事件和触摸手势

2019-04-28  本文已影响0人  79d12e22ec53

触屏事件和触摸手势

UIRsponder



import UIKit

class ViewController: UIViewController{

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let touch = touches.first
        let touchPoint = touch?.location(in: self.view)
        
    }
    
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        <#code#>
    }
    
    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        <#code#>
    }
    
    override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
        <#code#>
    }

}




UItouch 常用属性

view 触摸事件所在视图
timestamp 触摸事件发生时间戳
tapcountlocation 触摸事件点击次数
previousLocation 触摸事件在指定视图中上一次移动时候的位置
phase 触摸事件所在阶段
forse 触摸压力值,1.0表示普通
let view
view.isUserInteractionEnabled = true
let gesture = UITapGestureRecognizer
/*
UILongPressGestureRecognizer
UIPinchGestureRecognizer
*/
guesture.numberOfTapsRequired = 2 // 点击次数
guesture.numberOfTouchesRequired = 1 // 第几手指数量
上一篇 下一篇

猜你喜欢

热点阅读