测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
Release最后发布 | 2016 年 10 月 |
SPM支持 SPM | ✗ |
由 Kyle Bashour 维护。
这需要存在吗?可能不需要。其实很容易实现。但我已经多次寻找一个像 Twitter.app 那样动画的现有 presenter,却始终未能找到。所以,这里有一个,还有一些额外的选项!
将 import ElegantPresentations
添加到您的 presenting view controller 的顶部,并按照如下方式符合 UIViewControllerTransitioningDelegate
协议
// Conform to UIViewControllerTransitioningDelegate
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return ElegantPresentations.controller(presentedViewController: presented, presentingViewController: presenting, options: [])
}
// Set the delegate on the presented view controller
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
segue.destinationViewController.modalPresentationStyle = .Custom
segue.destinationViewController.transitioningDelegate = self
}
// Set the delegate whenever you instantiate the view controller
let destinationVC = storyboard!.instantiateViewControllerWithIdentifier("Compose")
destinationVC.modalPresentationStyle = .Custom
destinationVC.transitioningDelegate = self
presentViewController(destinationVC, animated: true, completion: nil)
查看示例项目以获取两种方法的示例,并确保查看 PresentationOption 枚举!例如,您可以用如下方式得到一个类似于 Mail.app 中 compose 的展示:
ElegantPresentations.controller(..., options: [. PresentedHeight(view.frame.height - 40)])
创建控制器的工厂方法需要一个选项集,它是一个 PresentationOption
的数组。它们都在示例项目中实现,并且易于切换来测试它们。
enum PresentationOption {
case NoDimmingView // Don't dim the presenting view controller
case DismissOnDimmingViewTap // Tapping outside the presented view controller dismisses it
case PresentingViewKeepsSize // Prevent the presenting view controller from shrinking back
case PresentedHeight(CGFloat) // Give the presented view controller a fixed height
case PresentedPercentHeight(Double) // Give the presented view controller a percent height (of the presenting view controller)
}
我刚开始制作库,所以如果我可以以任何方式改进它,请告诉我!开启一个 issue、提交一个 pull request,或者在 Twitter 上联系我。