Код: Выделить всё
struct ColorScroll: View {
private let colors = [Color.red, Color.blue, Color.green, Color.yellow, Color.brown, Color.indigo, Color.purple]
private let titles = ["Color.red", "Color.blue", "Color.green", "Color.yellow", "Color.brown", "Color.indigo", "Color.purple"]
var body: some View {
let itemWidth = 150.0
VStack(spacing: 20) {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 10) {
ForEach(colors.indices, id: \.self) { index in
ZStack {
RoundedRectangle(cornerRadius: 25.0)
.fill(colors[index])
.frame(width: itemWidth, height: 200)
.overlay(alignment: .leading) {
Text(titles[index])
.font(.title2)
}
.scrollTransition(.interactive, axis: .horizontal) { content, phase in
content.offset(x: phase.isIdentity ? 0 : phase.value * -itemWidth/2)
}
}
.clipShape(RoundedRectangle(cornerRadius: 25))
}
}
.scrollTargetLayout()
.padding(.horizontal, 20)
}
.frame(height: 200)
Spacer()
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... transition