UIPinchGestureRecognizer
捏是兩指手勢,其中手指彼此靠近或遠離。此手勢通常用於調整檢視大小。
迅速
override func viewDidLoad() {
super.viewDidLoad()
// Pinch
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(_:)))
pinchView.addGestureRecognizer(pinchGesture)
}
// Pinch action
func handlePinch(gesture: UIPinchGestureRecognizer) {
label.text = "Pinch recognized"
if gesture.state == UIGestureRecognizerState.Changed {
let transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale)
pinchView.transform = transform
}
}
筆記
- 這裡可以找到更完整的專案示例。