我想禁用缩小,我已经尝试通过设置最小值在UIScrollView上通过故事板进行操作,但它没有任何区别。
let tap = UIPinchGestureRecognizer(target: self, action: #selector(self.pinchHandler(gesture:)))
tap.delegate = self as? UIGestureRecognizerDelegate
self.scrollView.addGestureRecognizer(tap)
@objc private func pinchHandler(gesture: UIPinchGestureRecognizer) {
if let view = gesture.view {
switch gesture.state {
case .changed:
self.navigationController?.isNavigationBarHidden = true
let pinchCenter = CGPoint(x: gesture.location(in: view).x - view.bounds.midX,
y: gesture.location(in: view).y - view.bounds.midY)
let transform = view.transform.translatedBy(x: pinchCenter.x, y: pinchCenter.y)
.scaledBy(x: gesture.scale, y: gesture.scale)
.translatedBy(x: -pinchCenter.x, y: -pinchCenter.y)
view.transform = transform
gesture.scale = 1
case .ended:
UIView.animate(withDuration: 0.2, animations: {
view.transform = CGAffineTransform.identity
self.navigationController?.isNavigationBarHidden = false
})
default:
return
}
}
}
答案 0 :(得分:0)
所以要重申Quoc在评论中提到的内容,你的代码应该有点像这样 -
@objc private func pinchHandler(gesture: UIPinchGestureRecognizer) {
if let view = gesture.view {
switch gesture.state {
case .changed:
if(gesture.scale < 1.0) { return }
//your code
case .ended:
//your code
default:
return
}
}
}