Last active
November 21, 2021 20:25
-
-
Save dimkagithub/5c38e3c9d895f9b1b1aeb32fa7f1267f to your computer and use it in GitHub Desktop.
CATransition Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CATransition { | |
func segueFromBottom() -> CATransition { | |
self.duration = 0.375 //set the duration to whatever you'd like. | |
self.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) | |
self.type = CATransitionType.moveIn | |
self.subtype = CATransitionSubtype.fromTop | |
return self | |
} | |
func segueFromTop() -> CATransition { | |
self.duration = 0.375 //set the duration to whatever you'd like. | |
self.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) | |
self.type = CATransitionType.moveIn | |
self.subtype = CATransitionSubtype.fromBottom | |
return self | |
} | |
func segueFromLeft() -> CATransition { | |
self.duration = 0.1 //set the duration to whatever you'd like. | |
self.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) | |
self.type = CATransitionType.moveIn | |
self.subtype = CATransitionSubtype.fromLeft | |
return self | |
} | |
func popFromRight() -> CATransition { | |
self.duration = 0.1 //set the duration to whatever you'd like. | |
self.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) | |
self.type = CATransitionType.reveal | |
self.subtype = CATransitionSubtype.fromRight | |
return self | |
} | |
func popFromLeft() -> CATransition { | |
self.duration = 0.1 //set the duration to whatever you'd like. | |
self.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) | |
self.type = CATransitionType.reveal | |
self.subtype = CATransitionSubtype.fromLeft | |
return self | |
} | |
} | |
let nav = self.navigationController //grab an instance of the current navigationController | |
DispatchQueue.main.async { //make sure all UI updates are on the main thread. | |
nav?.view.layer.add(CATransition().segueFromLeft(), forKey: nil) | |
nav?.pushViewController(YourViewController(), animated: false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment