-1

i'm having a navigationcontroller that contains a button. when this button is pressed i would like to slide in new view from the right, with the current sliding out left on the same time. Exactly like if u have horizontal scrolling scrollview. Default NavigationController animation seem to just push the new view on top of the other. is there anyway to easily achieve this ?

Peter Pik
  • 11,023
  • 19
  • 84
  • 142
  • Also, you can find [here](https://github.com/onmyway133/fantastic-ios-animation/blob/master/Animation/transition.md) some cool examples of how to implement custom transitions – Leonardo Dec 14 '17 at 19:25

1 Answers1

0

Implement a custom segue between first and second view controllers and do this in perform method

override func perform() {
// Assign the source and destination views to local variables.
var firstVCView = self.sourceViewController.view as UIView!
var secondVCView = self.destinationViewController.view as UIView!

// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height

// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(screenWidth, 0 , screenWidth, screenHeight)

// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)

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

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

}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87