我希望協議從繼承來自Apple協議UIViewControllerTransitioningDelegate
,添加其他協議要求併爲該協議中的某些方法提供默認實現。當我這樣做時,方法不會被調用。當我在類中實現方法時,方法做被調用。當協議擴展現有的Apple API協議時,不會調用協議擴展方法
這裏就是我說的:
class FirstViewController: UIViewController, SlideDismissor {
let transition: PercentDrivenInteractiveTransitionWithState? = PercentDrivenInteractiveTransitionWithState()
}
protocol SlideDismissor: UIViewControllerTransitioningDelegate {
var transition: PercentDrivenInteractiveTransitionWithState? { get }
}
extension SlideDismissor {
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return nil // I do return something here, but for this example it isn't necessary
}
func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return transition
}
}
如果我添加以下代碼的函數都被調用。
extension FirstViewController: UIViewControllerTransitioningDelegate {
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return nil // I do return something here, but for this example it isn't necessary
}
func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
return transition
}
}
這些方法我試圖提供一個默認實現是可選的方法。
我也嘗試過爲UIView提供默認實現ControllerTransitioningDelegate' – Mingming