【发布时间】:2019-09-26 17:05:32
【问题描述】:
我正在玩 SwiftUI,但我被困在这个视图上。一切正常,但这个小错误非常令人沮丧。我试图将图像显示为垂直视图,它不会显示在视图上。我知道图像已加载,但视图未显示。它被蓝色覆盖。
import SwiftUI
struct PlanetHome : View {
var planets : [Planet]
var body : some View {
NavigationView {
ScrollView {
ZStack {
Color.black .edgesIgnoringSafeArea (.all)
VStack (alignment: .center)
{
ForEach (self.planets.identified(by: \.imageName))
{
planet in NavigationLink (destination: PlanetDetail(planets: planet))
{
PlanetsView (planets: planet)
.frame (width: 500, height: 500)
.padding (.vertical, 5)
}
}
}
}
}
.navigationBarTitle (Text("Planets"))
}
}
}
我试图将 NavigationView 放在 ZStack 下,但它不起作用。我不知道我在代码上做错了什么。调试器上没有错误消息。只是不显示图像。
【问题讨论】:
-
您的代码缺少最有趣的部分 ;-) 请包括 Planet、PlanetDetail 和 PlanetsView。跨度>
-
这可能是测试版中的一个错误。我想我已经看到它在我的项目中来来去去。这里有一些讨论:forums.developer.apple.com/thread/119809,但列出的修复对我不起作用
-
我在这里找到了解决方案:stackoverflow.com/questions/56541718/… 在 Image 上添加 .renderingMode(.original),我猜它在您的 PlanetsView 中
-
这个“功能”让我的 UIImage 全部显示为纯白色块。我一直在指责 Kingfisher 和其他图书馆,直到我发现这个。谢谢!
标签: swiftui