我希望在列表中向下滚动时隐藏底部搜索栏,所以我做了这个:
VStack{
List(searcherViewModel.stock, id: \.id){ number in
VStack{
StockCardView(stock: number)
}
.padding(.bottom, number.id == searcherViewModel.stock.last?.id ? .paddingForBottomNav : 0 )
.listRowSeparator(.hidden)
.listRowBackground(Color.background)
}
.listStyle(.plain)
.onTapGesture {
hideKeyboard()
}
}
.simultaneousGesture(
DragGesture()
.onChanged{ gesture in
print("Hey!")
withAnimation {
hideSearchBar = (gesture.location.y - gesture.startLocation.y < 0) //<- HERE I HIDE SEARCH BAR IF SCROLLING DOWN
}
}
)
但是手势只有在从静态开始时才能正确识别,如果您快速向上和向下移动它不会更新。