
I'm using matchedGeometryEffect as follows:
Код: Выделить всё
HStack(spacing: 15) {
ForEach(categories, id: \.self) { category in
let isSelected = selectedVal == category
Button {
withAnimation {
selectedVal = category
}
} label: {
VStack(spacing: 4) {
Text(category)
.frame(width: 100)
if isSelected {
RoundedRectangle(cornerRadius: 5)
.frame(width: 50, height: 2)
.matchedGeometryEffect(id: "Category", in: animation, isSource: isSelected)
}
}
}
}
}
Код: Выделить всё
HStack(spacing: 15) {
ForEach(categories, id: \.self) { category in
let isSelected = selectedVal == category
VStack(spacing: 4) {
Button(category) {
withAnimation {
selectedVal = category
}
}
if isSelected {
RoundedRectangle(cornerRadius: 5)
.frame(width: 50, height: 2)
.matchedGeometryEffect(id: "Category", in: animation, isSource: isSelected)
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/649 ... etry-group
Мобильная версия