测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
Released最新版本 | 2017年1月 |
SwiftSwift版本 | 3.0 |
SPM支持SPM | ✗ |
由cocoatoucher维护。
为 iOS 创建自定义 UIViewController 转换的简单且整洁的方式
通过提供过渡代理闭包回调和使用您的 UIView 动画代码,无需限制和处理实现 UIViewControllerAnimatedTransitioning 协议或继承 UIPercentDrivenInteractiveTransition 的复杂性,即可创建为你定制的视图控制器转换。
示例和屏幕截图中所使用的向下拖动图标来自 IconMafia(thenounproject.com) (https://thenounproject.com/search/?q=drag&i=463918)
嵌入式框架需要 iOS 8.1 以上的最低部署目标
如果您正在针对 iOS 7 进行项目开发,或者您不希望使用 CocoaPods,则必须将
AICustomViewControllerTransition.swift
源文件直接包含在您的项目中。
如果您不想您的转换是交互式的
let mySimpleTransitioningDelegate = SimpleTransitioningDelegate()
如果您的转换也想要交互式的话。它包含了 SimpleTransitioningDelegate 的所有功能。
let myInteractiveTransitioningDelegate = InteractiveTransitioningDelegate()
为将您的模态视图控制器显示出来的动画进行动画。请参考 Example 项目中的 SimpleTransitionViewController 示例。
mySimpleTransitioningDelegate.transitionPresent = { [weak self] (fromViewController: UIViewController, toViewController: UIViewController, containerView: UIView, transitionType: TransitionType, completion: @escaping () -> Void) in
UIView.animate(withDuration: animationDuration, animations: {
// Your custom presentation animation here
// Use provided viewController views to animate
}, completion: { (finished) in
// Do't forget to execute completion closure
completion()
})
}
为将您的模态视图控制器关闭的动画进行动画。请参考 Example 项目中的 SimpleTransitionViewController 示例。
mySimpleTransitioningDelegate.transitionDismiss = { [weak self] (fromViewController: UIViewController, toViewController: UIViewController, containerView: UIView, transitionType: TransitionType, completion: @escaping () -> Void) in
UIView.animate(withDuration: animationDuration, animations: {
// Your custom dismissal animation here
// Use provided viewController views to animate
}, completion: { (finished) in
completion()
})
}
为将您的模态视图控制器显示出来的百分比驱动交互式转换进行动画。请参考 Example 项目中的 PanToViewTransitionViewController 和 ExpandingCellsTableViewController 示例。
myInteractiveTransitioningDelegate.transitionPercentPresent = {[weak self] (fromViewController: UIViewController, toViewController: UIViewController, percentage: CGFloat, containerView: UIView) in
// Animate your view controllers using provided percentage
// Because the transition is progressive, you probably don't need an animation block here
}
通过百分比驱动的交互式过渡来关闭您的模态视图控制器。请参阅示例项目中的PanToViewTransitionViewController和ExpandingCellsTableViewController示例。
myInteractiveTransitioningDelegate.transitionPercentDismiss = {[weak self] (fromViewController: UIViewController, toViewController: UIViewController, percentage: CGFloat, containerView: UIView) in
// Animate your view controllers using provided percentage
// Because the transition is progressive, you probably don't need an animation block here
}
如果您正在使用InteractiveTransitioningDelegate作为过渡委托,请使用以下方法。请参阅示例项目中的PanToViewTransitionViewController和ExpandingCellsTableViewController示例。
开始呈现模态视图控制器,通常在您的用户与之交互的手势识别器的回调方法中。
myInteractiveTransitioningDelegate.beginPresenting(viewController:myModalViewController, fromViewController:self)
更新过渡的百分比,通常在您的用户与之交互的手势识别器的回调方法中。
myInteractiveTransitioningDelegate.update(percentage)
结束呈现或关闭交互式过渡。
myInteractiveTransitioningDelegate.finalizeInteractiveTransition(isTransitionCompleted:true)
如果您不是以交互式方式呈现视图控制器,则可以像平常一样呈现视图控制器。即使您使用InteractiveTransitioningDelegate,您也可以选择以渐进式的用户交互来自动呈现或关闭视图控制器,例如,用户只需单击一次按钮。请参阅示例项目中的PanToViewTransitionViewController。
myModalViewController.modalPresentationStyle = .Custom
myModalViewController.transitioningDelegate = myInteractiveTransitioningDelegate //or mySimpleTransitioningDelegate
self.presentViewController(self.detailViewController, animated: true, completion: nil)
http://cocoadocs.org/docsets/AICustomViewControllerTransition/
AICustomViewControllerTransition是在MIT许可证下发布的。有关详细信息,请参阅LICENSE。
youtube, fancy