首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UITransitionView在ViewController上使用UIModalPresentationStyle.OverCurrentContext

使用UITransitionView在ViewController上使用UIModalPresentationStyle.OverCurrentContext
EN

Stack Overflow用户
提问于 2015-05-08 00:32:53
回答 1查看 5.7K关注 0票数 2

我试图在另一个之上设置一个视图控制器,同时保持第一个视图控制器的可见性。

但是,我看不到第一个,因为我有一个UITransitionView,上面有一个UIView (第一个在层次结构中,这就是我知道.OverCurrentContext正在工作的原因)

这应该是一个非常简单的代码,我不知道发生了什么。我知道我不能碰UITransitionView,这就是为什么我不知道该怎么做。

代码语言:javascript
复制
let vc = storyBoard.instantiateInitialViewController() as MyPresenterViewController
vc.view.backgroundColor = .clearColor()
vc.modalPresentationStyle = .OverCurrentContext

viewControllerToPresentIn.presentViewController(vc, animated: true, completion: nil)

如有建议,将不胜感激。

诚挚的问候,

EN

回答 1

Stack Overflow用户

发布于 2017-05-15 07:11:09

这个反应有点晚了,但我最近遇到了一个类似的问题。我想要呈现的一种模式(带有半透明的面纱)被一个白色的UITransitionView所包含,隐藏着潜在的视图。我怀疑在某些情况下,当您发出一个TransitionView调用以显示您的模式时,会注入此controller.present() (但不知道原因或时间)。

作为一个快速和肮脏的解决方法,您可以尝试在出现之前清除您的模式的父视图的背景。由于某些原因,UITransitionView也会得到一个清晰的颜色,一旦你呈现你的模式。

代码语言:javascript
复制
extension UIView {
   //This will eventually get to the UITransitionView and clear the background.
   func clearHierarchyBackground() {
    self.backgroundColor = .clear
    if let superView = self.superview {
        superview.clearHierarchyBackground()
    }
  }
}

let parentController = MyParentViewController()
let childController = MyModalViewController()
childController.modalPresentationStyle = .overFullScreen //.overCurrentContext should also work..
childController.view.clearHierarchyBackground() 
/* The above makes your controller root view .clear
so you need to add subviews with transparency & 
content as you see fit.*/
parentController.present(childController, animated:true....)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30113897

复制
相关文章

相似问题

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