我想學習一些新的iOS編程模式。我已經閱讀了關於在iOS 7中添加的UIViewController轉換API的一些內容。它們看起來很酷,但對於看起來更簡單的任務來說,它們感覺相當沉重。瞭解UIViewController轉換的值
考慮這個用例: 我有一個自定義容器視圖控制器來管理「幻燈片」。它包含一組幻燈片視圖控制器,用戶可以通過點擊按鈕前後移動。
我可以完成這個過渡如下:
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值多爲互動的轉變?
感謝澄清
我同意有許多獨立的類,乍一看API看起來令人望而生畏。但是,Apple的文檔涵蓋了所有的低級語言,並且你需要爲每個類寫入的代碼數量(比如說)複製'UIAlertController'的行爲並不是很多。 –