How to present view controller from right to left in iOS using Swift

前端 未结 12 1231
悲&欢浪女
悲&欢浪女 2020-12-04 06:03

I am using presentViewController to present new screen

let dashboardWorkout = DashboardWorkoutViewController()
presentViewController(dashboardWorkout, anima         


        
12条回答
  •  孤街浪徒
    2020-12-04 06:29

    import UIKit and create one extension for UIViewController:

    extension UIViewController {
    func transitionVc(vc: UIViewController, duration: CFTimeInterval, type: CATransitionSubtype) {
        let customVcTransition = vc
        let transition = CATransition()
        transition.duration = duration
        transition.type = CATransitionType.push
        transition.subtype = type
        transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        view.window!.layer.add(transition, forKey: kCATransition)
        present(customVcTransition, animated: false, completion: nil)
    }}
    

    after simlpy call:

    let vC = YourViewController()
    transitionVc(vc: vC, duration: 0.5, type: .fromRight)
    

    from left to right:

    let vC = YourViewController()
    transitionVc(vc: vC, duration: 0.5, type: .fromleft)
    

    you can change the duration with your preferred duration...

提交回复
热议问题