Questions tagged [uihostingcontroller]
78 questions
1
vote
0 answers
UIHostingController auto layout during UIViewControllerTransitioningDelegate?
I have the following code:
import UIKit
import SwiftUI
class ViewController: UIViewController {
@IBOutlet weak var testButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup…

zumzum
- 17,984
- 26
- 111
- 172
1
vote
0 answers
SwiftUI View is not updating when @Published changed in ObservableObject
I know there are a lot of questions out there with similar issues but almost all of them are reference/value issues. My case is a little different
I have a Viewcontroller that leverages UIHostingController and add's a SwiftUI view.
I have a…

SpaceDust__
- 4,844
- 4
- 43
- 82
1
vote
1 answer
Dismiss SwiftUI View Embedded in UINavigationController
I am experiencing an issue when deep linking into a certain SwiftUI view from a link. the openTakeVC is what is called when deep linked. Currently it was to be embedded in a UINavigationController in order to work, if I try just presenting the…

Noah Iarrobino
- 1,435
- 1
- 10
- 31
1
vote
0 answers
How to correctly make 2-way binding with UITableViewRepresentable and SwiftUI
I'm creating my own custom SwiftUI List because I need to use some underlying methods of tableview. I would like to know how to correctly bind a TextField inside a UITableView Cell to my SwiftUI ViewModel.
So basically I have a textfield inside a…

Tony
- 91
- 4
1
vote
1 answer
SwiftUI View blended over UIViewController's view
I have an iOS app with a MetalView contained in a UIViewController, all setup in a story board.
Now I want to blend over the metal view another SwiftUI view, which is transparent. So only the GUI elements of the SwiftUI view are visible to the user…

Chris
- 1,231
- 2
- 10
- 20
1
vote
1 answer
Push to UIViewController from SwiftUI
My app is a hybrid of UIKit & SwiftUI. I have a use case where a user may need to tap on a Button from a SwiftUI.View but push to a UIViewController or another UIHostingController.
My project uses Storyboard.
I'm using UINavigationController &…

Luke Irvin
- 1,179
- 1
- 20
- 39
1
vote
1 answer
iOS 14: Scene lifecycle events not getting hit after setting the application root view controller in SwiftUI @main
My test code:
import SwiftUI
@main
struct TestingIOS14App: App {
@Environment(\.scenePhase) var scenePhase
var body: some Scene {
WindowGroup {
ContentView()
.withHostingWindow { window in
…

Miki
- 329
- 4
- 10
1
vote
0 answers
Hot to set additional safe area insets in SwiftUI
I'm trying to add additional padding to safe area dynamically. To achieve this I wrote modifier that wraps SwiftUI view into UIHostingController and sets additionalSafeAreaInsets on them:
extension View {
func extendSafeArea() -> some View {
…

Mark Kotevode
- 31
- 1
- 3
1
vote
0 answers
Can UISwipeGestureRecognizer work for view in UIHostingController?
As per answer in https://stackoverflow.com/a/64726641/3286489, I can perform a swipe down to dismiss a fullscreen ViewController using UISwipeGestureRecognizer.
However, when I transfer the same code to UIHostingController as below, it doesn't work…

Elye
- 53,639
- 54
- 212
- 474
1
vote
0 answers
How detect subview is Button in UIHostingController - SwiftUI
I need to get a button from the SwiftUI view that is wrapped in UIHostingController. In UIKit we simply could check the type in this way:
for (id subview in subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
//do code for UIKit
…

Mac3n
- 4,189
- 3
- 16
- 29
1
vote
1 answer
SwiftUI: How to get the HostingController View/Content maxHeight by given width?
I'm trying to get the maxHeigth of an UIHostingController-View/Content and know only the width.
I want to create a PDF Document based on my view. Everything works fine but I don't know how to get the maxHeight of the view/content so the PDF knows…

schnitz
- 33
- 4
1
vote
1 answer
Should I call viewDidLoad() inside updateUIViewController(_:context:) in SwiftUI
I create UIScrollView to be integrated inside SwiftUI view. It contains UIHostingController to host SwiftUI view. When I update UIHostingController, UIScrollView does not change its constraints. I can scroll neither to top nor to bottom. When I try…

Dscyre Scotti
- 1,307
- 10
- 17
0
votes
1 answer
UIHostingView failed to present view, which already presenting
I create the custom alert, but when I try to show it on .sheet View, I have this error -
2023-08-05 00:21:15.880778+0200 MyApp[759:72430] [Presentation] Attempt to present <_TtGC7SwiftUI19UIHostingControllerV6Events11CustomAlert_: 0x108009600> on…

developer
- 3
- 2
0
votes
1 answer
Presenting SwiftUIView sheet with height fitting content size from UIViewcontroller
I need to present a sheet containing SwiftUI view from UIViewController, but the height of the sheet has to fit the height of the content of the SwiftUI view.
I know that there is a possibility to specify custom detent for the height of the sheet,…
0
votes
0 answers
Is it best to use multiple UIHostingControllers for nesting multiple SwiftUI views within a UIViewController?
Below is how you add a SwiftUI view to a UIViewController.
However, I have not seen any examples where someone adds two separate SwiftUI views to the same UIViewController.
Is the below approach advisable? I'm concerned that adding a lot of…

Plato
- 111
- 2
- 7