【问题标题】:How to drop an object on a bar button item?如何将对象放在条形按钮项上?
【发布时间】:2018-04-11 19:46:18
【问题描述】:

我有this 集合视图,我希望能够通过在栏右侧的垃圾栏按钮中拖动单元格来删除它。

我不明白如何使按钮能够接收掉落, 如果是 UIView 我可以做

addInteraction(UIDropInteraction(..))

但由于它是一个按钮,我不能这样操作。

有人可以帮助我吗?

【问题讨论】:

  • UIButton 继承自 UIControl,而 UIControl 继承自 UIView,因此您可以对 UIView 执行的任何操作也可以对 UIButton 执行。
  • 是的,但这是一个 UIBarButtonItem,所以我不能使用 addInteraction
  • 现在看到了抱歉。

标签: ios swift ipad drag-and-drop


【解决方案1】:

您可以尝试创建自定义视图并向其添加交互。最后,将其添加到 rightBarButtonItem。大概是这样的:

func viewDidLoadForBarButton() {
        let customView = UIView() //Add your custom UIView() here
        customView.sizeToFit()

        let dropInteraction = UIDropInteraction(delegate: self)
        customView.addInteraction(dropInteraction)
        let barButton = UIBarButtonItem(customView: customView)
        self.navigationItem.rightBarButtonItem = barButton
    } 

让我知道它是否有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    相关资源
    最近更新 更多