Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modalPresentationStyle .overCurrentContext causing issues with remote button presses on presented view controller

I am having an issue with using the .overCurrentContext modalPresentationStyle on a tvOS view controller:

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

On the presented view controller, pressing the menu button ceases to return to the presenting view controller. This also occurs when setting it to .overFullScreen and .blurOverFullScreen. However, I am having no such problem when setting it to .currentContext or .fullScreen. Is there anything particular that needs to be used when using certain UIModalPresentationStyle's?

like image 904
Daniel Smith Avatar asked Nov 17 '17 16:11

Daniel Smith


1 Answers

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)

So what's going on here? The definesPresentationContext property was added in iOS 8, and the documentation states the following:

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.

By setting definesPresentationContext to YES you ensure that the controller to be presented is presented within the bounds of the original view controller.

like image 114
Daniel Lyon Avatar answered Oct 18 '22 19:10

Daniel Lyon