我正在開發一個圖書館,我想提供兩個視圖控制器之間的默認定製化,用戶也可以提供自己的實現,它涉及到我的腦海裏的第一個想法是重寫UIViewController
和實施UIViewControllerTransitioningDelegate
然後用戶可以繼承我的CustomTransitionViewController
是否是實現它的最佳方式?任何限制?有沒有更優雅的方式使用協議,例如默認實現?默認自定義轉換爲UIViewController中
import UIKit
class CustomTransitionViewController: UIViewController, UIViewControllerTransitioningDelegate {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.transitioningDelegate = self
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil:Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.transitioningDelegate = self
}
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return FadeInAnimator(transitionDuration: 0.5, startingAlpha: 0.8)
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return FadeInAnimator(transitionDuration: 0.5, startingAlpha: 0.8)
}
}