Shawn Frank
Shawn Frank

Reputation: 5213

Thin horizontal white lines appear when presenting a SwiftUI view embedded in a Hosting Controller from UIKit

I have a SwiftUI view called a paywall view.

I create and present it from UIKit view controller like this:

let paywallView = PaywallView()
let hostingController = UIHostingController(rootView: paywallView)
hostingController.modalPresentationStyle = .fullScreen
self.present(hostingController, animated: true)

Everything works fine and as expected, however, during the presentation transition / animation, these horizontal thin white lines appear and they go away once the animation is complete.

During the transition SwiftUI Hosting Controller present from UIKit

After the transition SwiftUI Hosting Controller present from UIKit

Side note: There is no navigation bar, navigation view or navigation stack in the SwiftUI view.

Any idea why this happens and how to solve this ?

Upvotes: 3

Views: 163

Answers (1)

cohen72
cohen72

Reputation: 3000

Set the backgroundColor of the hosting controller's view as follows:

let hostingController = UIHostingController(rootView: rootView)
hostingController.view.backgroundColor = .clear

Upvotes: 0

Related Questions