Reputation: 91
I have a UIPinchGestureRecognizer that allows a user to scale a UITextView. That all works with the following code:
@IBAction func handlePinch(recognizer : UIPinchGestureRecognizer) {
if let view = recognizer.view {
view.transform = CGAffineTransformScale(view.transform,
recognizer.scale, recognizer.scale)
recognizer.scale = 1
}
}
However, I only want the user to be able to make the UITextView larger, not smaller. I have set my UIGestureRecognizerDelegate and have put in the following code:
func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
if let pinch = gestureRecognizer as? UIPinchGestureRecognizer {
return pinch.scale < 1
}
return true
}
I got that code from this post here: UIPinchGestureRecognizer only for pinching out.
However, my method never gets called and it is not working. Any thoughts?
Upvotes: 5
Views: 6276
Reputation: 28952
Make sure to include UIGestureRecognizerDelegate
in your class declaration:
class ViewController: UIViewController, UIGestureRecognizerDelegate { /* ... */ }
Then, set your gestureRecognizer
's delegate to self
:
gestureRecognizer.delegate = self
Hope that helps :)
Upvotes: 12