View2ViewTransition
这是一个简单的框架,用于从视图到另一个视图的自定义交互视图控制器过渡。
安装
Carthage
github "naru-jpn/View2ViewTransition"
CocoaPods
pod 'View2ViewTransition'
用法
创建 TransitionController 并实现展示
// Create TransitionController
var transitionController: TransitionController = TransitionController()
// Present view controller with transition delegate
let presentedViewController: PresentedViewController = PresentedViewController()
presentedViewController.transitioningDelegate = transitionController
transitionController.present(viewController: presentedViewController, on: self, attached: presentedViewController, completion: nil)
(也支持推送)
// Set transitionController as a navigation controller delegate and push.
let presentedViewController: PresentedViewController = PresentedViewController()
if let navigationController = self.navigationController {
navigationController.delegate = transitionController
transitionController.push(viewController: presentedViewController, on: self, attached: presentedViewController)
}
展示的视图控制器遵循 View2ViewTransitionPresenting 协议
func initialFrame(userInfo: [String: AnyObject]?, isPresenting: Bool) -> CGRect
func initialView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> UIView
func prepereInitialView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> Void // (optional)
展示的视图控制器遵循 View2ViewTransitionPresented 协议
func destinationFrame(userInfo: [String: AnyObject]?, isPresenting: Bool) -> CGRect
func destinationView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> UIView
func prepareDestinationView(userInfo: [String: AnyObject]?, isPresenting: Bool) -> Void // (optional)
使用 UserInfo
你可以设置 userInfo 来通知 indexPath 或共享资源等。
transitionController.userInfo = ["key": "value", ...]
修改动画参数
使用自定义动画参数来动画化。
// For present
transitionController.presentAnimationController.usingSpringWithDamping = 0.7
transitionController.presentAnimationController.initialSpringVelocity = 0.0
transitionController.presentAnimationController.animationOptions = [.CurveEaseInOut]
// For dismiss
transitionController.dismissAnimationController.usingSpringWithDamping = 0.7
transitionController.dismissAnimationController.initialSpringVelocity = 0.0
transitionController.dismissAnimationController.animationOptions = [.CurveEaseInOut]
调试模式
如果你在App中有分层视图控制器(导航控制器),则遵循协议的viewController不直观。View2ViewTransition在调试模式下打印一些信息。
let transitionController = TransitionController()
// ...
transitionController.debuging = true