MatchTransition 1.3.0

MatchTransition 1.3.0

Lorenzo Toscani De Col维护。



  • 作者:
  • LorTos

这是什么?

此 Pod 允许您在

  • cell (UITableViewCellUICollectionViewCell) 和详情 UIViewController 之间创建自定义转换
  • 两个 UIViewController

使用模态 present(UIViewController, animated: Bool, completion: nil)UINavigationController 推送。

示例项目

该项目包含了每种类型的转换示例。要运行示例项目,克隆仓库,并在 Example 目录中运行pod install

用法

在您想要开始转换的viewController中创建一个转换管理器。

let manager = MatchTransitionManager()

一旦您想要推送或展示一个新的 UIViewController,实例化它

let storyboard = UIStoryboard(name: "StoryboardName", bundle: nil)
let detailsViewController = storyboard.instantiateViewController(withIdentifier: "DetailsControllerIdentifier") as! DetailsControllerClass
  • Cell 到详情 UIViewController 设置

当您想要从 cell 开始动画时,获取 selectedCell

let selectedCell = collectionView.cellForItem(at: indexPath) as! YourCellClass

设置你的 [Match]

let matches: [Match] = [
  Match(tag: "SomeUniqueName", from: selectedCell.someView, to: detailsViewController.someView),
  Match(tag: "OtherName", from: selectedCell.otherView, to: detailsViewController.otherView),
]

设置你的 MatchTransition

manager.setupTransition(from: selectedCell,
                        inside: self,
                        to: detailsViewController,
                        with: matches,
                        transitionType: TransitionType)
  • UIViewControllerUIViewController 的设置

创建你当前 UIViewController(self) 和详情 UIViewController 的视图之间的 [Match]

let matches: [Match] = [
  Match(tag: "SomeUniqueName", from: self.someView, to: detailsViewController.someView),
  Match(tag: "OtherName", from: self.otherView, to: detailsViewController.otherView),
]

设置你的 MatchTransition

manager.setupTransition(from: self,
                        to: destinationVC,
                        with: matches,
                        transitionType: TransitionType)
  • 选择 TransitionType 并启动过渡

设置 MatchTransition 时,您必须传递一个 TransitionType,它可以是 .modal.push

  • .modal 不需要进一步设置

    1. 简单地调用 present(detailsViewController, animated: true),然后让 MatchTransition 做工作!
  • .push 需要一些步骤才能顺利运行

    1. 参与过渡的两个 UIViewController 必须有 相同MatchTransitionManager 复制

    2. 在每个控制器的 viewDidAppear() 中设置 navigationController?.delegate = self

    3. 在两个控制器中遵守 UINavigationControllerDelegate,根据您希望过渡发生的 operation返回管理器中的相应过渡。然后在所有其他情况下将委托设置为 nil 并返回 nil

    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
          if operation == .push {
              return manager.transition(for: .presenting)
          }
          navigationController.delegate = nil
          return nil
    }
    1. 现在您可以调用 push(detailsViewController, animated: true) 并享受过渡!

常见问题解答

  • Match 是什么?它是一个对象,用于连接两个视图,其中一个来自初始 ViewController 或单元,另一个来自详情 ViewController。要创建一个,只需提供一个 唯一的标签,并传递两个视图。
Match(tag: "SomeUniqueName", from: selectedCell.someView, to: detailsViewController.someView)

技巧

  • 始终在单元的 contentView 和详情 ViewControllerview 之间添加一个 Match

  • 您数组中 Match 的顺序非常重要!它决定了视图在过渡中的显示顺序,是其他视图之前还是之后

  • 在类型为 .push 的过渡的情况下,两个控制器必须具有管理器的 相同 实例

安装

MatchTransition 通过 CocoaPods 提供。要安装它,只需在您的 Podfile 中添加以下行:

pod 'MatchTransition'

然后运行 pod install

作者

LorTos, [email protected]

许可证

MatchTransition 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。