Search code examples
iosswiftsegueswipe

Black Screen on Segue Animation / Glitchy & Extend swipe gesture length


I have been following a tutorial on how to implement custom segues. Using a swipe gesture - I swipe my finger the segue works but instead of a smooth transition where the second ViewController slides upwards/downwards to replace the current one, I get a black screen then the destination ViewController loads..

This happens on both the forward and the rewind segue.

I have attached the animation code for my normal segue (not rewind).

Additonally, when I swipe the screen slightly the segue happens instantaneously. How would I make it so the segue does not occur until my finger is lifted off (or in the simulators case, the mouse click). Would I have to work with scrollViews? or is this effect possible just using swipeGestureRecognizers & custom segues.

Thanks!

class FirstCustomSegue: UIStoryboardSegue {

override func perform() {

    // Animate the transition.
    UIView.animateWithDuration(0.4, animations: { () -> Void in
        firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
        secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)

        }) { (Finished) -> Void in

            // Animate the transition.
            UIView.animateWithDuration(0.4, animations: { () -> Void in
                firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
                secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)

                }) { (Finished) -> Void in
                    self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                        animated: false,
                        completion: nil)
            }
       }
   }

}

Solution

  • Try this code, I changed the last line on self.destinationViewController...

    class FirstCustomSegue: UIStoryboardSegue {
    
        override func perform() {
    
            // Animate the transition.
            UIView.animateWithDuration(0.4, animations: { () -> Void in
                firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
                secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)
    
                }) { (Finished) -> Void in
    
                    // Animate the transition.
                    UIView.animateWithDuration(0.4, animations: { () -> Void in
                        firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
                        secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)
    
                        }) { (Finished) -> Void in
                            self.sourceViewController.presentViewController(self.storyboard.instantiateViewControllerWithIdentifier("YOUR_IDENTIFIER"),
                                animated: false,
                                completion: nil)
                    }
            }
        }
    
    }
    

    Replace YOUR_IDENTIFIER with the storyboard ID that matches your view controller.