3

のない私は(のUIViewControllerのサブクラス)を提示するためにいくつかのカスタムモーダルプレゼンテーションやカスタムコントローラを持っています。これは、自身の移行代行者であり、アニメーション化された移行オブジェクトとプレゼンテーションコントローラを返します。アニメーション化されたトランジションオブジェクトを使用して、プレゼンテーション時にコンテナビューにプレゼンテーションビューを追加し、ディスミッシング時にプレビュービューを削除し、もちろんアニメーション化します。プレゼンテーションコントローラを使用して、いくつかのヘルパーサブビューを追加します。カスタムビューコントローラのプレゼンテーションアニメーション

public final class PopoverPresentationController: UIPresentationController { 
    private let touchForwardingView = TouchForwardingView() 

    override public func presentationTransitionWillBegin() { 
     super.presentationTransitionWillBegin() 
     self.containerView?.insertSubview(touchForwardingView, atIndex: 0) 
    } 
} 

public final class PopoverAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning { 

    func setupView(containerView: UIView, presentedView: UIView) { 
     //adds presented view to container view 
    } 

    public func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
     //1. setup views 
     //2. animate presentation or dismissal 
    } 
} 

public class PopoverViewController: UIViewController, UIViewControllerTransitioningDelegate { 

    init(...) { 
     ... 
     modalPresentationStyle = .Custom 
     transitioningDelegate = self 
    } 

    public func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return PopoverAnimatedTransitioning(forPresenting: true, position: position, fromView: fromView) 
    } 

    public func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return PopoverAnimatedTransitioning(forPresenting: false, position: position, fromView: fromView) 
    } 

    public func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController?, sourceViewController source: UIViewController) -> UIPresentationController? { 
     return PopoverPresentationController(presentedViewController: presented, presentingViewController: presenting, position: position, fromView: fromView) 
    } 

} 

私はpresentViewControllerとコントローラを提示し、animatedプロパティにtrueを渡したときにすべてが正常に動作します。しかし、アニメーションなしでプレゼンテーションしてfalseを渡したい場合、UIKitはpresentationControllerForPresentedViewControllerメソッドを呼び出すだけで、animationControllerForPresentedControllerを呼び出すことはありません。また、提示されたビューがビュー階層に追加され、決して作成されないアニメーション遷移オブジェクト内に配置される限り、何も提示されない。私がやっている何

は、遷移がアニメ化された場合、私はプレゼンテーションコントローラにチェックしていると私は手動でオブジェクトを移行し、セットアップビューにそれを作るのアニメーション作成しない場合です。

override public func presentationTransitionWillBegin() { 
    ... 
    if let transitionCoordinator = presentedViewController.transitionCoordinator() where !transitionCoordinator.isAnimated() { 
     let transition = PopoverAnimatedTransitioning(forPresenting: true, position: position, fromView: fromView) 
     transition.setupView(containerView!, presentedView: presentedView()!) 
    } 
} 

これはうまくいきますが、それが最善のアプローチかどうかはわかりません。

ドキュメントは、プレゼンテーションコントローラのみアニメーション移行対象に行われるべきで推移し、プレゼンテーションのための主な仕事中に任意の追加のセットアップやアニメーションを行うための責任を負うべきであると述べています。

はそれではなく、唯一のアニメーション移行オブジェクトでそれらをアニメーションプレゼンテーションコントローラで常にセットアップビューにOKですか?

は、その問題を解決するための任意のより良い方法はありますか?プレゼンテーションコントローラにアニメーション遷移からビューセットアップのすべてのロジックを移動することによって、その解決

答えて

1

関連する問題