我使用视图控制器包含来管理一组子视图控制器,这些子视图控制器应该能够以自定义的方式以模式方式呈现其他视图控制器。
我遇到了一个问题,当使用definesPresentationContext的视图控制器呈现时,不使用UIModalPresentationStyle.custom属性。
例如,我有三个视图控制器:ROOT、A和B
ROOT
|_ AA是ROOT的孩子。我想在使用自定义的B、UIViewControllerTransitioningDelegate和UIViewControllerAnimatedTransitioning的同时,从A模型中呈现出UIPresentationController。
因此,我在控制器A的代码中执行以下操作(注意控制器A将definesPresentationContext设置为true):
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
这导致iOS正确地从A读取definesPresentationContext属性,现在使用正确的from视图控制器调用我的animateTransition函数,但是:
由于我的模式表示风格不再是.custom,所以在转换委托中的以下方法不再被称为
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?所以我的演示控制器就不用了。
我想要一种尊重.custom的definesPresentationContext模式转换风格。这个是可能的吗?我是不是遗漏了什么?
基本上,我希望在当前上下文中有一个自定义的模态表示。
发布于 2017-08-01 21:57:32
在您的UIPresentationController子类中,按照以下方式重写shouldPresentInFullscreen:
override var shouldPresentInFullscreen: Bool {
get {
return false
}
}根据UIPresentationController头:
// 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;这一点和definesPresentationContext一起应该能起作用。
https://stackoverflow.com/questions/42060290
复制相似问题