SwiftUI:如何使内容与屏幕顶部对齐,但保留后退按钮
SwiftUI: How to get content aligned to top of screen, but keep back button
我正在学习 SwiftUI(Swift 5,目标 iOS 13.2)
问)如何才能让我的照片(和下面的内容)在缺口区域后面对齐?
到目前为止我在模拟器中得到了什么:
如您所见,我已经了解了如何使用内联导航栏样式。
我想要什么
查看代码:
import SwiftUI
struct DrinkDetail: View {
var drink: Drink
var body: some View {
List {
ZStack(alignment: .bottom) {
Image(drink.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
Rectangle()
.frame(height: 80.0)
.opacity(0.75)
.blur(radius: 10)
HStack {
Text(drink.name)
.font(.largeTitle)
.foregroundColor(.white)
.padding(8)
Spacer()
}
}
.listRowInsets(EdgeInsets())
Text(drink.description)
.font(.body)
.foregroundColor(.primary)
.lineLimit(nil)
.padding(.bottom, 50.0)
.lineSpacing(12)
HStack {
Spacer()
Button(action: {}) {
Text("Order me")
}
.frame(width: 200.0, height: 50.0)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
Spacer()
}
}
.edgesIgnoringSafeArea(.top)
.navigationBarTitle(Text(""), displayMode: .inline)
}
}
看起来这根本不可能,尽管我之前看过的教程显示它是可能的。
除非另行通知,这是唯一的方法:
我正在学习 SwiftUI(Swift 5,目标 iOS 13.2)
问)如何才能让我的照片(和下面的内容)在缺口区域后面对齐?
到目前为止我在模拟器中得到了什么:
如您所见,我已经了解了如何使用内联导航栏样式。
我想要什么
查看代码:
import SwiftUI
struct DrinkDetail: View {
var drink: Drink
var body: some View {
List {
ZStack(alignment: .bottom) {
Image(drink.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
Rectangle()
.frame(height: 80.0)
.opacity(0.75)
.blur(radius: 10)
HStack {
Text(drink.name)
.font(.largeTitle)
.foregroundColor(.white)
.padding(8)
Spacer()
}
}
.listRowInsets(EdgeInsets())
Text(drink.description)
.font(.body)
.foregroundColor(.primary)
.lineLimit(nil)
.padding(.bottom, 50.0)
.lineSpacing(12)
HStack {
Spacer()
Button(action: {}) {
Text("Order me")
}
.frame(width: 200.0, height: 50.0)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
Spacer()
}
}
.edgesIgnoringSafeArea(.top)
.navigationBarTitle(Text(""), displayMode: .inline)
}
}
看起来这根本不可能,尽管我之前看过的教程显示它是可能的。
除非另行通知,这是唯一的方法: