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
}
}
笔记
- 这里可以找到更完整的项目示例。