SpringAnimationController
provides a subtle way to spice up the default modal presentation style on iOS using spring animations. Simply implement the UIViewControllerTransitioningDelegate
protocol and return this animation controller to add some bounce at the top of your modal presentation.
First, set up the view controller that you want to present modally and trigger the model presentation as you normally would.
let viewControllerToPresent = PresentedViewController()
viewControllerToPresent.transitioningDelegate = self
viewControllerToPresent.modalPresentationStyle = .custom
present(viewControllerToPresent, animated: true)
Next, implement UIViewControllerTransitioningDelegate
to return an instance of SpringyAnimationController
func animationController(forPresented presented: UIViewController,
presenting: UIViewController,
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let bouncyTransition = SpringAnimationController(isPresenting: true)
return bouncyTransition
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let bouncyTransition = SpringAnimationController(isPresenting: false)
return bouncyTransition
}
You can also customize the animation duration, spring damping and spring velocity before returning the animation controller.
let bouncyTransition = SpringAnimationController(isPresenting: true)
bouncyTransition.transitionDuration = 0.35
bouncyTransition.springDamping = 0.5
bouncyTransition.springVelocity = 0.7
To run the example project, simply run pod try SpringAnimationController
.
iOS 10 and above
SpringAnimationController is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SpringAnimationController'
SpringAnimationController is available under the MIT license. See the LICENSE file for more info.