Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detacting Pinch and Rotation gestures simultaneously

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)
like image 241
SpaceShroomies Avatar asked Dec 15 '22 13:12

SpaceShroomies


2 Answers

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
like image 170
Bohdan Savych Avatar answered Feb 05 '23 01:02

Bohdan Savych


Just added this and it works:

func gestureRecognizer(UIGestureRecognizer,
        shouldRecognizeSimultaneouslyWithGestureRecognizer:UIGestureRecognizer) -> Bool {
            return true
    }
like image 40
SpaceShroomies Avatar answered Feb 05 '23 03:02

SpaceShroomies