Abhi V Abhi V - 1 year ago 56
iOS Question

UIRotationGestureRecognizer activates multiple times Swift

When using

the rotation is recognized but it triggers the action multiple times. Here is my code:

override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
let rotation = UIRotationGestureRecognizer(target: self, action: #selector(ViewController.lol))

func lol() {
print ("hi")
UIView.animateWithDuration(5.0, animations: {
let currTransform = self.view.transform
let newTransform = CGAffineTransformConcat(currTransform, CGAffineTransformMakeRotation(CGFloat(M_PI)))
self.view.transform = newTransform


Answer Source

Check out UIRotationGestureRecognizer's state.

let rotation = UIRotationGestureRecognizer(target: self, action: #selector(ViewController.lol(_:)))

func lol(sender: UIRotationGestureRecognizer) {

I expect you're just receiving Began and End states.