UinavigationController hat Swiftui Image und Asyncimage gebrochenIOS

Programmierung für iOS
Guest
 UinavigationController hat Swiftui Image und Asyncimage gebrochen

Post by Guest »

Ich integriere Swiftui in uIinAvigationController und begegnet seltsames Problem, wenn ich einen UiHostingController mit einem langen Bild oder Asyncimage enthält. Ich möchte

Code: Select all

      Image("picsum-237-1900x400")
.resizable()
.scaledToFill()
.frame(height: 200)
.frame(maxWidth: .infinity)
Diese Anzeige wird normalerweise mit dem üblichen NavigationStack und navigationLink angezeigt. Aber wenn ich es mit NavigationWrapper verwende, überläuft das Bild auf dem Bildschirm.

Code: Select all

struct NavigationWrapper: UIViewControllerRepresentable {
@ViewBuilder let rootView: () -> Content

func makeUIViewController(context: Context) -> UINavigationController {
let navController = UINavigationController()
let hostingController = UIHostingController(
rootView: rootView().environment(\.navigationController, navController)
)
navController.pushViewController(hostingController, animated: false)
return navController
}

func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
}

< /code>
Verwendung: < /p>
@main
struct MainApp: App {
var body: some Scene {
WindowGroup {
NavigationWrapper(rootView: { ProductView() })
}
}
}

struct ProductView: View {
@Environment(\.navigationController) private var navigationController

var body: some View {
VStack {
Button("Go to Product Details") {
let hostingVC = UIHostingController(rootView: ProductDetailsScreen())
navigationController?.pushViewController(hostingVC, animated: true)
}
}
.navigationTitle("Products")
}
}

struct ProductDetailsScreen: View {
var body: some View {
VStack {
Image("picsum-237-1900x400")
.resizable()
.scaledToFill()
.frame(height: 200)
.frame(maxWidth: .infinity)
Spacer()
Text("Product Details")
Spacer()
}
.navigationTitle("Details")
}
}

struct NavigationControllerKey: EnvironmentKey {
static let defaultValue: UINavigationController? = nil
}

extension EnvironmentValues {
var navigationController: UINavigationController? {
get { self[NavigationControllerKey.self] }
set { self[NavigationControllerKey.self] = newValue }
}
}

Um die Demonstration zu vereinfachen, habe ich ein Bild ähnlich groß heruntergeladen und Bild anstelle von Asyncimage :

Gibt es einige Konzepte, die ich an der Überbrückung von Swiftui fehlt, und uikit, oder ist das ein Fehler in Swiftui und gibt es eine Problemumgehung dafür?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post