SwiftUI

SwiftUI ScrollView onLongPressGesture手势 卡住的问题

我们在ScrollView里面,添加onLongPressGesture手势后,会发现和ScrollView本身的滚动冲突。

在onLongPressGesture{} 之前 加上onTapGesture{} 可以解决问题

struct ContentView: View
{
  let data = [
    "Test 1","Test 2","Test 3","Test 4","Test 5",
    "Test 6","Test 7","Test 8","Test 9","Test 10",
    "Test 11","Test 12","Test 13","Test 14","Test 15",
    "Test 16","Test 17","Test 18","Test 19","Test 20"
  ]

  var body: some View
  {
    List
    {
      ForEach(data,id:\.self)
      {
        item in
       // 在onLongPressGesture{} 之前 加上onTapGesture{}可以解决问题
        Text(item).onTapGesture{}.onLongPressGesture{}
      }
    }
  }
}