Skip to content

pietrorea/SpringAnimationController

Repository files navigation

SpringAnimationController

Version License Platform

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.

Demo

Usage

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

Example

To run the example project, simply run pod try SpringAnimationController .

Requirements

iOS 10 and above

Installation Instructions

SpringAnimationController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SpringAnimationController'

License

SpringAnimationController is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published