【问题标题】:modalPresentationStyle .overCurrentContext causing issues with remote button presses on presented view controllermodalPresentationStyle .overCurrentContext 导致在呈现的视图控制器上按下远程按钮时出现问题
【发布时间】:2017-11-17 16:17:28
【问题描述】:

我在 tvOS 视图控制器上使用 .overCurrentContext modalPresentationStyle 时遇到问题:

let vc = UIStoryboard(name: "", bundle: Bundle.main).instantiateInitialViewController() //representative of actually presented VC
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true, completion: nil)

在呈现的视图控制器上,按下菜单按钮停止返回到呈现的视图控制器。将其设置为.overFullScreen.blurOverFullScreen 时也会发生这种情况。但是,将其设置为.currentContext.fullScreen 时没有这样的问题。使用某些UIModalPresentationStyle's 时有什么特别需要使用的吗?

【问题讨论】:

  • 您展示的是哪种视图控制器?我注意到这也会导致焦点问题。例如,当呈现的视图控制器仍在呈现时,焦点被返回到呈现的视图控制器。

标签: swift uiviewcontroller tvos uimodalpresentationstyle


【解决方案1】:
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)

那么这里发生了什么?在 iOS 8 中添加了定义PresentationContext 属性,文档说明如下:

当一个视图控制器被呈现时,iOS 从呈现视图控制器开始并询问它是否想要提供呈现上下文。如果呈现视图控制器不提供上下文,则 iOS 会询问呈现视图控制器的父视图控制器。 iOS 向上搜索视图控制器层次结构,直到视图控制器提供表示上下文。如果没有视图控制器提供上下文,则窗口的根视图控制器提供表示上下文。

如果视图控制器返回 YES,那么它提供了一个表示上下文。由视图控制器的视图覆盖的窗口部分决定了呈现的视图控制器视图的大小。此属性的默认值为 NO。

通过将definePresentationContext 设置为YES,您可以确保要呈现的控制器显示在原始视图控制器的范围内。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多