触屏事件和触摸手势
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 // 第几手指数量
网友评论