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

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

I am using presentViewController to present new screen

let dashboardWorkout = DashboardWorkoutViewController()
presentViewController(dashboardWorkout, anima         


        
12条回答
  •  臣服心动
    2020-12-04 06:30

    You can also use custom segue.

    Swift 5

    class SegueFromRight: UIStoryboardSegue {
    
        override func perform() {
            let src = self.source
            let dst = self.destination
    
            src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
            dst.view.transform = CGAffineTransform(translationX: src.view.frame.size.width, y: 0)
    
            UIView.animate(withDuration: 0.25,
                   delay: 0.0,
                   options: UIView.AnimationOptions.curveEaseInOut,
                   animations: {
                        dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
                },
                       completion: { finished in
                        src.present(dst, animated: false, completion: nil)
            })
        }
    }
    

提交回复
热议问题