ElegantPresentations 2.0

ElegantPresentations 2.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Release最后发布2016 年 10 月
SPM支持 SPM

Kyle Bashour 维护。



  • 作者
  • Kyle Bashour

ElegantPresentations

这需要存在吗?可能不需要。其实很容易实现。但我已经多次寻找一个像 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: [])
}

如果您正在使用 Storyboards

// Set the delegate on the presented view controller

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    segue.destinationViewController.modalPresentationStyle = .Custom
    segue.destinationViewController.transitioningDelegate = self
}

如果您没有使用 Storyboards

// 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)
}

待办事项

  • [X] 适应旋转
  • [ ] 旋转时更好地动画显示 presenting view

贡献

我刚开始制作库,所以如果我可以以任何方式改进它,请告诉我!开启一个 issue、提交一个 pull request,或者在 Twitter 上联系我。