Dan*_*ith 5 uiviewcontroller uimodalpresentationstyle swift tvos
我在使用.overCurrentContext modalPresentationStyletvOS视图控制器时遇到问题:
let vc = UIStoryboard(name: "", bundle: Bundle.main).instantiateInitialViewController() //representative of actually presented VC
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在呈现的视图控制器上,按下菜单按钮将停止返回到呈现视图控制器.将其设置为.overFullScreen和时也会发生这种情况.blurOverFullScreen.但是,在将其设置为.currentContext或时,我没有遇到此类问题.fullScreen.在使用某些特定UIModalPresentationStyle的东西时,是否有任何特殊需要使用?
let vc = UIStoryboard(name: "", bundle: Bundle.main).instantiateInitialViewController() //representative of actually presented VC
vc.modalPresentationStyle = .overCurrentContext
self.definesPresentationContext = true //*** adding this line should solve your issue ***
self.present(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
那么这是怎么回事呢?DefinePresentationContext 属性是在 iOS 8 中添加的,文档说明如下:
当呈现视图控制器时,iOS 从呈现视图控制器开始并询问它是否想要提供呈现上下文。如果呈现视图控制器不提供上下文,则 iOS 会询问呈现视图控制器的父视图控制器。iOS 在视图控制器层次结构中向上搜索,直到视图控制器提供呈现上下文。如果没有视图控制器提供上下文,则窗口的根视图控制器提供呈现上下文。
如果视图控制器返回 YES,则它提供呈现上下文。视图控制器的视图覆盖的窗口部分决定了所呈现的视图控制器的视图的大小。该属性的默认值为“否”。
通过将 DefinesPresentationContext 设置为 YES,您可以确保要呈现的控制器在原始视图控制器的范围内呈现。
| 归档时间: |
|
| 查看次数: |
1046 次 |
| 最近记录: |