【发布时间】:2016-07-27 22:01:04
【问题描述】:
我正在尝试学习一些新的 iOS 编程模式。我已经阅读了一堆关于 iOS 7 中添加的 UIViewController 转换 API 的内容。它们看起来很酷,但对于看似更简单的任务来说也感觉相当沉重。
考虑这个用例: 我有一个管理“幻灯片”的自定义容器视图控制器。它拥有一系列幻灯片视图控制器,用户可以通过点击按钮来向前和向后移动它们。
我可以按如下方式实现转换:
private func transitionToViewController(viewController: UIViewController, direction: TransitionDirection = .Forward, animated: Bool = true) {
currentViewController.willMove(toParentViewController: nil)
addChildViewController(viewController)
// ... set up frames, other animation prep ...
contentContainerView.addSubview(comingView)
UIView.animate(duration: 0.5, animations: {
// do the animations
}) { (finished) in
leavingView.removeFromSuperview()
self.currentViewController.removeFromParentViewController()
viewController.didMove(toParentViewController: self)
// final clean up
}
}
新的过渡 API 将如何改进这一点?据我了解,如果您正在滚动自己的容器视图控制器,这些 API 的使用会更加复杂(参见 custom-container view controller transitions。
过渡 API 中的值是否主要用于交互式过渡?
感谢澄清
【问题讨论】:
标签: ios swift uiviewcontroller uiviewanimationtransition