gpt4 book ai didi

ios - SwiftUI 导航链接和 ScrollView 问题

转载 作者:行者123 更新时间:2023-11-29 05:14:07 25 4
gpt4 key购买 nike

我的导航链接和 SwiftUI 有问题。导航栏消失,我的 ScrollView 上升。我已在 Facebook 上上传了该问题的视频,链接为:the link of the video

enter image description here

这是我的主视图的代码:

    struct MainView: View {

let date = Date()
let calendar = Calendar.current


static let formatter: DateFormatter = {


let formatter = DateFormatter()

formatter.dateStyle = .medium

formatter.timeStyle = .short

return formatter

}()

//MARK: Properties
@ObservedObject var session = FirebaseSession()

let user = Auth.auth().currentUser

@State private var showModal = false

var body: some View {
NavigationView{
// Group {

ZStack {
if session.session != nil {
ScrollView {
VStack{
ScrollView(.horizontal, showsIndicators: false){
HStack{
NavigationLink(destination: RedactorView()) {
RedactorListItem()
}.buttonStyle(PlainButtonStyle())
RedactorListItem()
RedactorListItem()
RedactorListItem()
RedactorListItem()
RedactorListItem()
}//.padding()
}
VStack(alignment: .leading, spacing: 5) {
HStack {
Text("Les derniers médias")
.font(.largeTitle)
.bold()
Spacer()
Text("Voir plus >")
.padding(8)
.background(Color(UIColor.secondarySystemBackground))
.clipShape(Capsule())
}.padding(.horizontal)
ScrollView(.horizontal, showsIndicators: false){
HStack{
NavigationLink(destination: MotherView(viewRouter: ViewRouter())){
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
}.buttonStyle(PlainButtonStyle())
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()


}
}

HStack {
Text("Les derniers articles :")
.font(.largeTitle)
.bold()
Spacer()
Text("Voir plus >")
.padding(8)
.background(Color(UIColor.secondarySystemBackground))
.clipShape(Capsule())

}.padding(.horizontal)

ArticleListRow()
ArticleListRow()
ArticleListRow()

}

}


.navigationBarTitle("WYN")
.navigationBarHidden(true)
}.navigationViewStyle(StackNavigationViewStyle()).padding(.top, 90)

ZStack{
VStack{
HStack{
VStack(alignment: .leading) {

VStack {
VStack(alignment: .leading){

HStack{
Text("What You Need")
.font(.system(.largeTitle, design: .serif))
.bold()

Spacer()




Button(action: {
self.showModal.toggle()
}) {
Image(systemName: "person.crop.circle.fill")
.font(.largeTitle)
.foregroundColor(.primary)
}

.sheet(isPresented: $showModal){
SettingView(showModal: self.$showModal)
}
}

Text("\(date, formatter : MainView.self.formatter)")
.font(.callout)
.bold()
.foregroundColor(Color(UIColor.systemGray4))

}

/*
Rectangle()
.frame(height: 2)
.cornerRadius(1)
.foregroundColor(Color(UIColor.systemGray5))

*/

}
.padding(.horizontal)
.padding(.top, 20)

}.background(Color(UIColor.systemBackground)).frame(minWidth: 0, maxWidth: .infinity).frame(height: 75)
}
Spacer()
}
}

} else {
Authentification()
}
}
.onAppear(perform: getUser)

//}
.navigationBarTitle("Menu Principal")
.navigationBarHidden(true)
}.navigationViewStyle(StackNavigationViewStyle())
}

//MARK: Functions
func getUser() {
session.listen()
}

}

这是我的详细 View 的代码:


import SwiftUI

struct RedactorView: View {
var body: some View {
// NavigationView {
ScrollView {
VStack(alignment: .leading) {
HStack{
Image("P1")
.resizable()
.scaledToFill()
.frame(width: 115, height: 115)
.clipShape(Circle())

.padding(.trailing)
VStack(alignment: .leading){
Text("Prénom")
.font(.largeTitle)
.bold()
Text("Nom")
.font(.largeTitle)
.bold()
HStack {
VStack(alignment: .center){
Text("10")
.bold()
Text("Articles")
.foregroundColor(Color(UIColor.secondaryLabel))
}
VStack(alignment: .center){
Text("5")
.bold()
Text("Medias")
.foregroundColor(Color(UIColor.secondaryLabel))
}
}.padding(.top)
}
Spacer()
}.padding(.horizontal)
ScrollView(.horizontal, showsIndicators: false) {
HStack {
HStack{
Text("Email")

.bold()
Image(systemName: "envelope.fill")
// .foregroundColor(Color(UIColor.systemBlue))
}.foregroundColor(Color(UIColor.systemBlue))
.padding(8)
.background(Color(UIColor.systemBackground))
.clipShape(Capsule())
.shadow(color: Color(UIColor.systemGray6), radius: 10)
HStack{
Text("Instagram")

.bold()
Image(systemName: "heart.fill")


}.foregroundColor(Color(hue: 0.93, saturation: 0.81, brightness: 0.84)).padding(8)
.background(Color(UIColor.systemBackground))
.clipShape(Capsule())
.shadow(color: Color(UIColor.systemGray6), radius: 10)
HStack{
Text("Message")

.bold()

Image(systemName: "message.fill")


}.foregroundColor(Color(UIColor.systemGreen))
.padding(8)
.background(Color(UIColor.systemBackground))
.clipShape(Capsule())
.shadow(color: Color(UIColor.systemGray6), radius: 10)
HStack{
Text("Téléphone")

.bold()
Image(systemName: "phone.fill")

}.foregroundColor(Color(UIColor.systemGreen)).padding(8)
.background(Color(UIColor.systemBackground))
.clipShape(Capsule())
.shadow(color: Color(UIColor.systemGray6), radius: 10)

}.padding()

}

VStack(alignment: .leading, spacing: 5) {
Text("Ses Medias :")
.font(.largeTitle)
.bold()
.padding(.leading)
ScrollView(.horizontal, showsIndicators: false){
HStack{

MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()
MediaListRow()
.frame(width: UIScreen.main.bounds.width/1.15)
.scaledToFit()

}
}
Text("Ses Articles :")
.font(.largeTitle)
.bold()
.padding(.leading)

ArticleListRow()
ArticleListRow()
ArticleListRow()
}
}.navigationBarTitle("Redactor")

}
// }//.padding(.top, -20)
}
}

我不知道这个问题的解决方案是什么,我希望它能正常打开,但它没有找到,而且我对所有 ScrollView 都有相同的解决方案。请帮我。

最佳答案

navigationView 上缺少一个 .edgesIgnoringSafeArea(.top),它可以为您提供 safeArea 防护。

关于ios - SwiftUI 导航链接和 ScrollView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59358785/

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