简体   繁体   中英

Segue Right Left transition

I have some code This is the code that describes the transition from left to right

class AGSegue: UIStoryboardSegue 
override func perform() {
    let sourceViewController = self.sourceViewController 
    let destinationViewController = self.destinationViewController 
    // Creates a screenshot of the old viewcontroller
    let duplicatedSourceView: UIView = sourceViewController.view.snapshotViewAfterScreenUpdates(false)

    // the screenshot is added above the destinationViewController
    destinationViewController.view.addSubview(duplicatedSourceView)

    sourceViewController.presentViewController(destinationViewController, animated: false, completion: {
        // it is added above the destinationViewController
        destinationViewController.view.addSubview(duplicatedSourceView)
        UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in
            // slides the sourceViewController to the right
            duplicatedSourceView.transform = CGAffineTransformMakeTranslation(sourceViewController.view.frame.size.width, 0)
            }) { (finished: Bool) -> Void in
                duplicatedSourceView.removeFromSuperview()
        }
    })

}

}

I need only a transition from right to left

To give the transition animation effect remove those hectic work which you have done and go for UINavigationViewController it will allows to push and pop animation for view and maintain the low disk space for every transition. If you want right to left transition for UIViewController then push that view into UINavigationViewController and for left to right transition pop view to root view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM