5

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?

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Daniel Smith
  • 51
  • 1
  • 3
  • What kind of view controller are you presenting? I've noticed this causing focus issues also. For example, focus being returned to the presenting view controller while presented view controller is still being presented. – Daniel Storm Aug 15 '18 at 12:53

1 Answers1

4
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.

Daniel Lyon
  • 1,499
  • 10
  • 15