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 ?
Asked
Active
Viewed 118 times
1 Answers
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
-
-
Storyboard is needed to create the custom segue between first and second controllers where you will assign the custom segue class to it that contains the perform method – Shehata Gamal Dec 14 '17 at 18:31