8

私はカスタムの方法で他のビューコントローラをモーダルに表示できるはずの子ビューコントローラのセットを管理するために、ビューコントローラの包含を使用しています。 ROOTA、およびBUIModalPresentationStyle.customでdefinesPresentationContextを使用する

:ビューコントローラからの提示は、一例として UIModalPresentationStyle.custom

を使用した場合

私はdefinesPresentationContextプロパティがを使用されていない問題に遭遇してきた、私は3つのView Controllerを持っています

ROOT |_ A 

Aは、ROOTの子です。私はAからモーダルでBを提示したいと思いますが、カスタムUIPresentationController,UIViewControllerTransitioningDelegate、およびUIViewControllerAnimatedTransitioningを使用しています。

だから私は、コントローラAのコード(注コントローラAtruedefinesPresentationContextセットを持っている)の内部で次のようにします(これも私のUIViewControllerAnimatedTransitioningである)私のプレゼンテーションコントローラ内部で、私は次のように遭遇、しかし

func buttonPressed(_ sender: Any?) { 
    let presentationController = MyCustomPresentation() 

    let controllerToPresent = B() 

    controllerToPresent.modalTransitionStyle = .custom 
    controllerToPresent.transitioningDelegate = presentationController 

    present(controllerToPresent, animated: true, completion: nil) 
} 

問題:この機能で

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
    let fromVC = transitionContext.viewController(forKey: .from) 
    let toVC = transitionContext.viewController(forKey: .to) 

    if let fromVC = fromVC as? A, 
     let toVC = toVC as? B { 
     //Do the presentation from A to B 
    } 
} 

、私はfromVCがタイプAであることを期待し、それが実際にはです。 AにはdefinesPresentationContextと指定されていますが。

だから私はUIModalPresentationStyle.customを使っているからです。だから私はUIModalPresentationStyle.overCurrentContext

これは正しくAからdefinesPresentationContextプロパティを読み取るためのiOSを引き起こし、私のanimateTransition機能は、現在のビューコントローラから正しいと呼び出されるに変更しませんが、:

私のモーダルプレゼンテーションスタイルはもはやですので.customは、私の移行デリゲートで、次の方法はもはや

func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? 

呼ばなかっますだから私のプレゼンテーションコントローラは未使用となります。

.customモーダルトランジションスタイルは、definesPresentationContextを尊重します。これは可能ですか?何か不足していますか?

基本的には、現在のコンテキスト内にカスタムモーダルプレゼンテーションが必要です。あなたのUIPresentationControllerサブクラスで

+0

移行代理人を「A」に設定しようとしましたか? この行の前: 'present(controllerToPresent、animated:true、completion:nil)'です。 この試す: 'UIModalPresentationStyle.overCurrentContext' – zero

答えて

0

、次のようにshouldPresentInFullscreenを上書き:UIPresentationControllerヘッダーを1として

override var shouldPresentInFullscreen: Bool { 
    get { 
     return false 
    } 
} 

を:definesPresentationContextとともに

// By default each new presentation is full screen. 
// This behavior can be overriden with the following method to force a current context presentation. 
// (Default: YES) 
@property(nonatomic, readonly) BOOL shouldPresentInFullscreen; 

これはトリックを行う必要があります。

+1

は、あなたの答えをありがとう: ' self.transitioningDelegate = presentationController' を使用したとき、私はこのことを示唆しています。私は自分のUIPresentationControllerサブクラスをチェックして、 'shouldPresentInFullscreen'に' false'を返していますが、プレゼンテーションコンテキストを定義しているツリーの下のビューコントローラにはまだ与えられておらず、代わりにルートVCを取得しています。 – simeon

関連する問題