0
override func viewDidAppear(animated: Bool) {

    view.userInteractionEnabled = true
    let pinchGesture:UIPinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: "pinchGesture")
    view.addGestureRecognizer(pinchGesture)

    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
    view.addGestureRecognizer(tap)
}

func dismissKeyboard() {
    view.endEditing(true)
}

func pinchGesture(){

    self.performSegueWithIdentifier("trick1Segue", sender: self)

}

In my iOS app, i want to transition to a different view controller when a pinch gesture is performed on the screen. The tap gesture is to dismiss the keyboard when tapped outside the keyboard area

While running the app, I get an error message:

"Attempting to present < ** > on < ** > while a presentation is in progress"

The new view controller appears but opens twice, with a very short time difference. Looked up a lot of blogs but couldn't find a solution, please help!!!

nikhil.g777
  • 882
  • 3
  • 12
  • 24

2 Answers2

0

The problem is that pinchGesture can be called multiple times. You should add a property to your viewController to keep track of the fact that you already have acted upon the pinch gesture:

var segueInProcess = false

func pinchGesture() {
    if !segueInProcess {
        self.performSegueWithIdentifier("trick1Segue", sender: self)
        segueInProcess = true
    }
}
vacawama
  • 150,663
  • 30
  • 266
  • 294
0

Gesture recognizers are called multiple times with different states. What you can do is check the state property of the UIPinchGestureRecognizer in pinchGesture().

Cai
  • 441
  • 4
  • 15