Reputation: 1635
I've successfully implemented gestures that allow users to enlarge and rotate a view using UIGuestureRecognizers. However, the user can't do two gestures at the same time (i.e. rotate and scale at the same time). How can I go about doing that? Below is how I added the gestures
var rotateRecognizer = UIRotationGestureRecognizer(target: self, action: "handleRotate:")
var pinchRecognizer = UIPinchGestureRecognizer(target: self, action: "handlePinch:")
testV.addGestureRecognizer(rotateRecognizer)
testV.addGestureRecognizer(pinchRecognizer)
Upvotes: 5
Views: 3818
Reputation: 1829
let rotateGesture = UIRotationGestureRecognizer(target: self, action: #selector(self.rotateGesture))
self.imageView.addGestureRecognizer(rotateGesture)
let pinchGesture = UIPinchGestureRecognizer(target: self, action:#selector(self.pinchGesture)) self.imageView.addGestureRecognizer(pinchGesture)
func rotateGesture(sender: UIRotationGestureRecognizer){
sender.view?.transform = (sender.view?.transform)!.rotated(by: sender.rotation)
sender.rotation = 0
print("rotate gesture")
}
func pinchGesture(sender: UIPinchGestureRecognizer){
sender.view?.transform = (sender.view?.transform)!.scaledBy(x: sender.scale, y: sender.scale)
sender.scale = 1
print("pinch gesture")
}
Upvotes: 3
Reputation: 3457
In swift 3 the delegate method name is:
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
Also you need set delegate for gestures:
rotateRecognizer.delegate = self
pinchRecognizer.delegate = self
Upvotes: 7
Reputation: 1635
Just added this and it works:
func gestureRecognizer(UIGestureRecognizer,
shouldRecognizeSimultaneouslyWithGestureRecognizer:UIGestureRecognizer) -> Bool {
return true
}
Upvotes: 3