微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift – modalPresentationStyle .overCurrentContext导致在呈现的视图控制器上按下远程按钮的问题

我在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,可确保要呈现的控制器显示在原始视图控制器的边界内.

快乐的编码!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐