【问题标题】:How to start drag immediately using UIDragInteraction?如何使用 UIDragInteraction 立即开始拖动?
【发布时间】:2018-08-07 07:23:20
【问题描述】:

我正在使用 UIDragInteraction,它运行良好。

let dragInteraction = UIDragInteraction(delegate: self)
myView.addInteraction(dragInteraction)
dragInteraction.isEnabled = true

正如预期的那样,当我长按 myView 时开始拖动。我现在想改变这种行为。我希望在触摸 myView 并移动手指时立即开始拖动,而不是长按?

我尝试使用平移手势来启动移动,但我不知道如何启动 dragInteraction。

let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panAction))
panGesture.minimumNumberOfTouches = 1
panGesture.maximumNumberOfTouches = 1
panGesture.cancelsTouchesInView = false
panGesture.delaysTouchesBegan = false
myView.addGestureRecognizer(panGesture)

请帮忙。谢谢。

【问题讨论】:

    标签: ios swift uipangesturerecognizer


    【解决方案1】:

    目前,标准的拖放实现似乎无法做到这一点。

    您可以降低与UIDragInteraction 关联的UILongPressGestureRecognizerminimumPressDuration。对此的进一步解释可以在这个答案中找到:set minimumPressDuration for UIDragInteraction

    除此之外,您始终可以使用手势识别器等实现自己的拖放交互。这当然可能很乏味,而且不是您想要的。

    【讨论】:

      猜你喜欢
      • 2017-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多