How to set content scroll view when using SwiftUI ScrollView in UIKit view controller?

I have a UIViewController that initially does not display any scrollable content, but later on I add a child view controller that does scroll - a UIHostingController whose rootView is a GeometryReader containing a ScrollView. The problem is when you scroll the UINavigationBar remains transparent I’m sure because it couldn’t find a scroll view in the view hierarchy. There is an API to specify which scroll view to use but that’s a UIScrollView. How can I tell it about my SwiftUI scroll view?

viewController.setContentScrollView(scrollView, for: .bottom)

Accepted Reply

I was able to get this to work in my scenario by reordering my subviews which caused it to be able to find the scroll view. I also filed feedback with a sample project to improve the logic so that’s not necessary.

Replies

I was able to get this to work in my scenario by reordering my subviews which caused it to be able to find the scroll view. I also filed feedback with a sample project to improve the logic so that’s not necessary.