我创建了可滚动的行,这些行已在ScrollView中列出。但是,当我尝试滚动ScrollView中的行列表时,将触发行滑动,并且禁用了滚动。我希望它能够识别我何时尝试滚动和何时滑动。
我尝试增加minimumDistance
,但这似乎无法解决。
有什么想法吗?
这是DragGesture
let swipe = DragGesture()
.onChanged { drag in
self.itemPosition += drag.translation.width - self.oldDragDistance
if self.itemPosition < 0 {
self.buttonsWidth = max(
self.buttonsWidth + -(drag.translation.width - self.oldDragDistance),
0
)
}
self.oldDragDistance = drag.translation.width
}
.onEnded { drag in
withAnimation(.easeInOut) {
if self.buttonsExpanded(at: self.itemPosition) {
self.itemPosition = -self.buttonsExpandedWidth
self.itemPositionOld = self.itemPosition
self.buttonsWidth = self.buttonsExpandedWidth
self.iconOpacity = 1
} else {
self.itemPosition = 0
self.itemPositionOld = self.itemPosition
self.buttonsWidth = 0
self.iconOpacity = 0
}
self.oldDragDistance = 0
}
}
我将其包含在ScrollView
ScrollView() {
ForEach(userData.items) { item in
ItemRow(rowHeight: 64.0, item: item)
}
}