微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

UIView最高点低于预期

如何解决UIView最高点低于预期

enter image description here

enter image description here

我遇到格式问题。我想要的是第二张图片,但是由于某种原因,我的视点开始降低了一点。您可以看到图片间的间隙。我想无偏移地解决这个问题。可能是因为.navigationBarHidden(true)导致的,但我不希望导航栏。

我在代码添加了NavigationView,因为我右下方有一个按钮来添加新任务。

加上由于某些原因,此按钮不可单击。如果您能解决这个问题,那将会很好。

import SwiftUI

struct TaskListView: View {
@State private(set) var data = ""
@State var isSettings: Bool = false
@State var isSaved: Bool = false
var body: some View {
    NavigationView {
        ZStack {
            Color(#colorLiteral(red: 0.9333333333,green: 0.9450980392,blue: 0.9882352941,alpha: 1)).edgesIgnoringSafeArea(.all)
            vstack {
                TopBar()
                HStack {
                    CustomTextField(data: $data,tFtext: "Find task",tFImage: "magnifyingglass")
                    Button(action: {
                        self.isSettings.toggle()
                    },label: {
                        ZStack {
                            RoundedRectangle(cornerRadius: 15)
                                .frame(width: 50,height: 50,alignment: .center)
                                .foregroundColor(Color(#colorLiteral(red: 0.4274509804,green: 0.2196078431,blue: 1,alpha: 1)))
                            Image("buttonImage")
                                .resizable()
                                .frame(width: 30,height: 30,alignment: .center)
                        }
                        .padding(.horizontal,15)
                    })
                }
                CustomSegmentedView()
                ZStack {
                    TaskFrameView()
                    Button( action: {
                        self.isSaved.toggle()
                    },label: {
                        ZStack {
                            RoundedRectangle(cornerRadius: 20)
                                .foregroundColor(Color(#colorLiteral(red: 1,green: 0.7137254902,blue: 0.2196078431,alpha: 1)))
                            Text("+")
                                .foregroundColor(.white)
                                .font(.title)
                                .fontWeight(.bold)
                        }
                        .frame(width: 40,height: 40)
                        .offset(x: 150,y: 220)
                    })
                    NavigationLink(
                        destination: NewTaskView(),isActive: $isSaved,label: {
                            Text("")
                        })
                }
            }
        }
        Spacer()
    }
      .navigationBarHidden(true)
    }
 }

struct TopBar: View {
  var body: some View {
      HStack {
         Image("avatar")
            .resizable()
            .frame(width: 100,height: 100)
        vstack(alignment: .leading){
            DateView()
                .font(Font.custom("SFCompactdisplay",size: 20))
                .foregroundColor(.gray)
                .padding(.vertical,5)
            Text("Hi,Random")
                .font(Font.custom("SFCompactdisplay",size: 20))
        }
        Image(systemName: "ellipsis")
       }
   }
}

解决方法

它是导航视图栏。 navigationBarHidden修饰符应位于内部 NavigationView,如

    }
    .navigationBarHidden(true) // << here !!
    Spacer()
} // end of NavigationView

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。