私はカスタムの方法で他のビューコントローラをモーダルに表示できるはずの子ビューコントローラのセットを管理するために、ビューコントローラの包含を使用しています。 ROOT
、A
、およびB
UIModalPresentationStyle.customでdefinesPresentationContextを使用する
UIModalPresentationStyle.custom
を使用した場合
私はdefinesPresentationContext
プロパティがを使用されていない問題に遭遇してきた、私は3つのView Controllerを持っています
ROOT |_ A
A
は、ROOT
の子です。私はA
からモーダルでB
を提示したいと思いますが、カスタムUIPresentationController
,UIViewControllerTransitioningDelegate
、およびUIViewControllerAnimatedTransitioning
を使用しています。
だから私は、コントローラA
のコード(注コントローラA
がtrue
にdefinesPresentationContext
セットを持っている)の内部で次のようにします(これも私の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
サブクラスで
移行代理人を「A」に設定しようとしましたか? この行の前: 'present(controllerToPresent、animated:true、completion:nil)'です。 この試す: 'UIModalPresentationStyle.overCurrentContext' – zero