SpringAnimationController
SpringAnimationController
通过弹簧动画提供了一种巧妙的方式,在 iOS 上增强默认模态呈现样式。简单实现 UIViewControllerTransitioningDelegate
协议并返回此动画控制器即可为您的模态呈现顶部添加一些弹性。
使用方法
首先,设置要模态呈现的视图控制器,并像平常一样触发模型呈现。
let viewControllerToPresent = PresentedViewController()
viewControllerToPresent.transitioningDelegate = self
viewControllerToPresent.modalPresentationStyle = .custom
present(viewControllerToPresent, animated: true)
接下来,实现 UIViewControllerTransitioningDelegate
并返回 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
}
返回动画控制器之前,您还可以自定义动画持续时间、弹簧阻尼和弹簧速度。
let bouncyTransition = SpringAnimationController(isPresenting: true)
bouncyTransition.transitionDuration = 0.35
bouncyTransition.springDamping = 0.5
bouncyTransition.springVelocity = 0.7
示例
要运行示例项目,只需运行 pod try SpringAnimationController
即可。
需求
iOS 10 及以上版本
安装说明
SpringAnimationController可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod 'SpringAnimationController'
许可证
SpringAnimationController在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。