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

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

概述我在tvOS视图控制器上使用.overCurrentContext modalPresentationStyle时遇到问题: let vc = UIStoryboard(name: "", bundle: Bundle.main).instantiateInitialViewController() //representative of actually presented VCvc.moda 我在tvOS视图控制器上使用.overCurrentContext modalPresentationStyle时遇到问题:

let vc = UIStoryboard(name: "",bundle: Bundle.main).instantiateInitialVIEwController() //representative of actually presented VCvc.modalPresentationStyle = .overCurrentContextpresent(vc,animated: true,completion: nil)

呈现的视图控制器上,按下菜单按钮将停止返回到呈现视图控制器.将其设置为.overFullScreen和.blurOverFullScreen时也会发生这种情况.但是,在将其设置为.currentContext或.fullScreen时,我没有遇到此类问题.使用某些UIModalPresentationStyle时是否需要使用任何特定的东西?

解决方法
let vc = UIStoryboard(name: "",bundle: Bundle.main).instantiateInitialVIEwController() //representative of actually presented VCvc.modalPresentationStyle = .overCurrentContextself.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,可确保要呈现的控制器显示在原始视图控制器的边界内.

快乐的编码!

@H_419_40@ 总结

以上是内存溢出为你收集整理的swift – modalPresentationStyle .overCurrentContext导致在呈现的视图控制器上按下远程按钮的问题全部内容,希望文章能够帮你解决swift – modalPresentationStyle .overCurrentContext导致在呈现的视图控制器上按下远程按钮的问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1006367.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存