Push to one viewcontroller from right to left animation iOS swift
Solution:
In my viewcontroller
let vc = mainBoard.instantiateViewController(withIdentifier: "myvc") as! myvc
self.changeVCWithAnimation(vc: vc)
extension UIViewController
func changeVCWithAnimation(vc: UIViewController) {
self.navigationController?.view.layer.add(getTransitionFromRight(), forKey: kCATransition)
self.navigationController?.pushViewController(vc, animated: false)
}
func getTransitionFromRight() -> CATransition {
return Transition.getTransition(timingFunction: CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut),transitionType: CATransitionType.moveIn, transitionSubType: CATransitionSubtype.fromRight)
}
}
struct Transition {
static func getTransition(timingFunction: CAMediaTimingFunction, transitionType: CATransitionType, transitionSubType: CATransitionSubtype) -> CATransition {
let transition:CATransition = CATransition()
transition.duration = 0.5
transition.timingFunction = timingFunction
transition.type = transitionType
transition.subtype = transitionSubType
return transition
}
}
Comments
Post a Comment