首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >definesPresentationContext与UIModalPresentationStyle.custom的结合

definesPresentationContext与UIModalPresentationStyle.custom的结合
EN

Stack Overflow用户
提问于 2017-02-06 04:24:49
回答 1查看 1.4K关注 0票数 12

我使用视图控制器包含来管理一组子视图控制器,这些子视图控制器应该能够以自定义的方式以模式方式呈现其他视图控制器。

我遇到了一个问题,当使用definesPresentationContext的视图控制器呈现时,不使用UIModalPresentationStyle.custom属性。

例如,我有三个视图控制器:ROOTAB

代码语言:javascript
复制
ROOT
 |_ A

AROOT的孩子。我想在使用自定义的BUIViewControllerTransitioningDelegateUIViewControllerAnimatedTransitioning的同时,从A模型中呈现出UIPresentationController

因此,我在控制器A的代码中执行以下操作(注意控制器AdefinesPresentationContext设置为true):

代码语言:javascript
复制
func buttonPressed(_ sender: Any?) {
    let presentationController = MyCustomPresentation()

    let controllerToPresent = B()

    controllerToPresent.modalTransitionStyle = .custom
    controllerToPresent.transitioningDelegate = presentationController

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

但是,在我的表示控制器(也是我的UIViewControllerAnimatedTransitioning)中,我遇到了以下问题:

代码语言:javascript
复制
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
    }
}

在这个函数中,我希望fromVCA类型的,实际上是ROOT。尽管A指定了definesPresentationContext

所以我想这是因为我使用的是UIModalPresentationStyle.custom。所以我把它改为UIModalPresentationStyle.overCurrentContext

这导致iOS正确地从A读取definesPresentationContext属性,现在使用正确的from视图控制器调用我的animateTransition函数,但是:

由于我的模式表示风格不再是.custom,所以在转换委托中的以下方法不再被称为

代码语言:javascript
复制
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?

所以我的演示控制器就不用了。

我想要一种尊重.customdefinesPresentationContext模式转换风格。这个是可能的吗?我是不是遗漏了什么?

基本上,我希望在当前上下文中有一个自定义的模态表示。

EN

回答 1

Stack Overflow用户

发布于 2017-08-01 21:57:32

在您的UIPresentationController子类中,按照以下方式重写shouldPresentInFullscreen

代码语言:javascript
复制
 override var shouldPresentInFullscreen: Bool {
     get {
         return false
     }
 }

根据UIPresentationController头:

代码语言:javascript
复制
// 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一起应该能起作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42060290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档