ビュー コントローラー コンテインメントを使用して、カスタムの方法で他のビュー コントローラーをモーダルに表示できる子ビュー コントローラーのセットを管理しています。
を使用してView Controllerから表示するときにdefinesPresentationContextプロパティが使用されないという問題に遭遇しましたUIModalPresentationStyle.custom
ROOT例として、 、A、およびの3 つのビュー コントローラーがあります。B
ROOT
|_ A
Aの子ですROOT。カスタム、、およびを使用してBからモーダルに表示したいと思います。AUIPresentationControllerUIViewControllerTransitioningDelegateUIViewControllerAnimatedTransitioning
したがって、コントローラーのコード内で次のことを行います(コントローラーが に設定されていることにA注意してください)。AdefinesPresentationContexttrue
func buttonPressed(_ sender: Any?) {
let presentationController = MyCustomPresentation()
let controllerToPresent = B()
controllerToPresent.modalTransitionStyle = .custom
controllerToPresent.transitioningDelegate = presentationController
present(controllerToPresent, animated: true, completion: nil)
}
ただし、私のプレゼンテーション コントローラー (これも私のUIViewControllerAnimatedTransitioning) 内で、次の問題が発生します。
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、実際にはROOTです。Aを指定しているにもかかわらず、definesPresentationContext.
を使っているからだと思いUIModalPresentationStyle.customます。だから私はそれをUIModalPresentationStyle.overCurrentContext
definesPresentationContextこれにより、iOS は からプロパティを正しく読み取るようAになり、animateTransitionビュー コントローラーから正しい関数が呼び出されるようになりましたが、次のようになります。
モーダル プレゼンテーション スタイルが ではなくなったため.custom、遷移中のデリゲートの次のメソッドが呼び出されなくなりました
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?
したがって、私のプレゼンテーションコントローラーは使用されなくなります。
.customを尊重するモーダル遷移スタイルが必要ですdefinesPresentationContext。これは可能ですか?何か不足していますか?
基本的に、現在のコンテキスト内でカスタム モーダル プレゼンテーションが必要です。