加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – modalPresentationStyle .overCurrentContext导致在呈

发布时间:2020-12-14 04:40:39 所属栏目:百科 来源:网络整理
导读:我在tvOS视图控制器上使用.overCurrentContext modalPresentationStyle时遇到问题: let vc = UIStoryboard(name: "",bundle: Bundle.main).instantiateInitialViewController() //representative of actually presented VCvc.modalPresentationStyle = .ove
我在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时是否需要使用任何特定的东西?

解决方法

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,completion: nil)

那么这里发生了什么?在iOS 8中添加了definesPresentationContext属性,文档说明了以下内容:

When a view controller is presented,iOS starts with the presenting view controller and asks it if it wants to provide the presentation context. If the presenting view controller does not provide a context,then iOS asks the presenting view controller’s parent view controller. iOS searches up through the view controller hierarchy until a view controller provides a presentation context. If no view controller offers to provide a context,the window’s root view controller provides the presentation context.

If a view controller returns YES,then it provides a presentation context. The portion of the window covered by the view controller’s view determines the size of the presented view controller’s view. The default value for this property is NO.

通过将definesPresentationContext设置为YES,可确保要呈现的控制器显示在原始视图控制器的边界内.

快乐的编码!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读