gpt4 book ai didi

ios - SwiftUI 删除 View 上的空格

转载 作者:行者123 更新时间:2023-12-01 16:06:03 24 4
gpt4 key购买 nike

在 SwiftUI View 中,我尝试显示一个简单的 TOP 蓝色条、一个红色矩形和一个下条,正如您从附图中看到的那样,顶部有一个奇怪的空白区域,顶部的红色矩形是我的想删除,但我不明白为什么会在那里。

SwiftUi

这是简单的代码:

    var body: some View {

GeometryReader { geometry in
VStack {
//upper top bar
HStack{
Text("TOP BAR")

}.frame(width: geometry.size.width, height: geometry.size.height/10)
.background(LinearGradient(gradient: Gradient(colors: [Color("BlueW"), Color("DARK")]), startPoint: .topLeading, endPoint: .bottomTrailing).shadow(radius: 2)).edgesIgnoringSafeArea(.all)

// <<<<<<<<<<<<<<<<<<< PROBLEM HERE <<<<<<<<<<<<<<<<<<
// testing rectangle
Rectangle().foregroundColor(.red)

//lower bar
ZStack {

HStack {
Image(systemName: "house")
.resizable()
.aspectRatio(contentMode: .fit)
.padding(20)
.frame(width: geometry.size.width/3, height: 75)
.foregroundColor(self.viewRouter.currentView == "home" ? .black : .gray)
.onTapGesture {
self.viewRouter.currentView = "home"
}
ZStack {
Circle()
.foregroundColor(Color.white)
.frame(width: 75, height: 75)
Button(action: {
self.isAddPresented = true
}) {
Image(systemName: "plus.circle.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 75, height: 75)
.foregroundColor(.green)
.rotationEffect(Angle(degrees: self.showPopUp ? 90 : 0))
}
.sheet(isPresented: self.$isAddPresented) {
AirportView(dm: self.dm, airport: self.general.airportData, dismissFlag: self.$isAddPresented)

}
}

.offset(y: -geometry.size.height/10/2)
.onTapGesture {
withAnimation {
self.showPopUp.toggle()
}

}
Image(systemName: "paperplane.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.padding(20)
.frame(width: geometry.size.width/3, height: 75)
.foregroundColor(self.viewRouter.currentView == "routekit" ? .black : .gray)
.onTapGesture {
self.viewRouter.currentView = "routekit"
}

}.frame(width: geometry.size.width, height: geometry.size.height/10)
.background(LinearGradient(gradient: Gradient(colors: [Color("BlueW"), Color("DARK")]), startPoint: .topLeading, endPoint: .bottomTrailing).shadow(radius: 2))
}
}

}.edgesIgnoringSafeArea(.bottom)
}

最佳答案

问题出在HStack使其边缘忽略所有安全区域( .edgesIgnoringSafeArea(.all) )。

enter image description here

如您所见,如果您检查 View ,您的绿色 View ( HStack )实际上位于 GeometryReader 内。 ,但它的框架在外面。

解决方法:删除.edgesIgnoringSafeArea(.all) .

新问题但是,顶部安全区域会有一个空白区域。

解决方案:

套装GeometryReader.edgesIgnoringSafeArea([.top, .bottom])
瞧!

enter image description here

关于ios - SwiftUI 删除 View 上的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60528331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com