0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SwiftUI】ScrollViewの子ViewにDragGestureがあるとScrollを認識しないなんてことある?

Posted at

発生したエラー

  • 動作上の不具合が発生した。
  • 子ComponentのDragGesutreはきちんと反応している一方で、親ViewのScrollViewが一切動かなくなってしまった。

当該のコード

親View.swift
ScrollView {
    // ForEachで画面が埋まるほど繰り返し生成されている
    Component()
}
子Component.swift
    //省略
    .gesutre(
        DragGesture()
    )

解決策

  • DragGestureminimumDistancecoordinateを設定する
  • coordinateはローカル座標系。このComponentViewだけに適用するという意図なら.localで良いと思われる。
DragGesture(minimumDistance: 30, coorindate: .local)

謝辞

You can set minimumDistance to some value (for instance 30). Then the drag only works when you drag horizontally and reach the minimum distance, otherwise the scrollview or list gesture override the view gesture

.gesture(DragGesture(minimumDistance: 30, coordinateSpace: .local)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?