Вот Минимальный воспроизводимый пример: < /p>
Код: Выделить всё
import SwiftUI
struct ContentView: View {
@State private var selectedTab: String? = "Tab 1"
var body: some View {
ScrollView(.vertical) {
LazyVStack {
Image(systemName: "photo.fill")
.resizable()
.aspectRatio(contentMode: .fill)
ScrollView(.horizontal) {
LazyHStack(spacing: 0) {
SampleView(.purple, 5)
.id("Tab 1")
.containerRelativeFrame(.horizontal)
SampleView(.red, 12)
.id("Tab 2")
.containerRelativeFrame(.horizontal)
SampleView(.blue, 20)
.id("Tab 3")
.containerRelativeFrame(.horizontal)
}
.scrollTargetLayout()
}
.scrollPosition(id: $selectedTab)
.scrollTargetBehavior(.paging)
}
}
}
@ViewBuilder
func SampleView(_ color: Color, _ size: Int) -> some View {
LazyVGrid(columns: Array(repeating: GridItem(), count: 2), content: {
ForEach(1...size, id: \.self) { _ in
RoundedRectangle(cornerRadius: 15)
.fill(color.gradient)
.frame(height: 150)
}
})
}
}
Вы можете увидеть из примера, высота горизонтального прокрутки заблокирована в разгар первого представления ребенка.
Подробнее здесь: https://stackoverflow.com/questions/782 ... osite-axis