ПРИМЕЧАНИЕ: < /strong> Обратите внимание, как следующие выступают все больше и больше по каждому слайду мы движемся вперед. Я не хочу игнорировать нижнюю безопасную область, только верхняя.
Как я могу исправить это поведение? Я предполагаю, что мне должен быть способ компенсировать это пространство при прокрутке на следующую страницу?
Код: Выделить всё
import SwiftUI
struct MainTabView: View {
var body: some View {
TabView {
Tab("Feed", systemImage: "house") {
FeedView()
}
Tab("Friends", systemImage: "person.2") {
Text("Friends Tab")
}
Tab("Create", systemImage: "plus") {
Text("Upload Tab")
}
Tab("Inbox", systemImage: "bell") {
Text("Inbox Tab")
}
Tab("Profile", systemImage: "person") {
Text("Profile Tab")
}
}
.tint(.white)
.onAppear {
let appearance = UITabBarAppearance()
appearance.backgroundColor = .black
// Use this appearance when scrolling behind the TabView:
UITabBar.appearance().standardAppearance = appearance
// Use this appearance when scrolled all the way up:
UITabBar.appearance().scrollEdgeAppearance = appearance
}
}
}
#Preview {
MainTabView()
}
< /code>
import SwiftUI
let colors = [Color.black, Color.blue, Color.green, Color.yellow, Color.red]
struct FeedView: View {
var body: some View {
ScrollView {
LazyVStack(spacing: 0) {
ForEach(0..
I have a "hacky" solution that I'm not sure why it works as this is my first ios app, but I found that adding .padding(.bottom, 1)Код: Выделить всё
...
struct FeedView: View {
var body: some View {
ScrollView {
...
}
.padding(.bottom, 1)
.ignoresSafeArea(edges: .top)
.scrollTargetBehavior(.paging)
.scrollBounceBehavior(.basedOnSize)
.scrollIndicators(.never)
.background(.black)
}
}
...
< /code>
Update:
One of the proposed approaches is to use .scrollTargetBehavior(.viewAligned(limitBehavior: .always))Первый рендеринг: < /p>
После взаимодействия схватывает на место:
Подробнее здесь: https://stackoverflow.com/questions/794 ... -the-top-s
Мобильная версия