如何在iPhone的自定义UIViews上启用UIDragInteraction [英] How to enable UIDragInteraction on Custom UIViews for iPhone

查看:214
本文介绍了如何在iPhone的自定义UIViews上启用UIDragInteraction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Apple的新API在自定义UIView上启用拖动交互.在使用iPad进行测试时,我设法使其正常运行,但是当我在iPhone 7-ios 11 beta 3中运行相同的应用程序时,无法拖动自定义UIViews.

I've been trying to use Apple's new API to enable Drag interactions on Custom UIViews. I've managed to make it work when testing using iPad, but when I run the same app in my iPhone 7 - ios 11 beta 3, I'm not able to drag my custom UIViews.

我注意到在UICollectionView和UITableViews中使用时,我们需要启用拖动交互

I've noticed that we need to enable drag interaction when using in UICollectionView and UITableViews

collectionView.dragInteractionEnabled = true tableView.dragInteractionEnabled = true

collectionView.dragInteractionEnabled = true tableView.dragInteractionEnabled = true

但是我无法在文档中或任何地方找到有关在自定义UIView中启用它以使其在iPhone上运行的任何信息.有谁知道一种为iPhone的自定义UIView启用拖动交互的方法?

but I can't manage to find anything in the documentation or anywhere about enabling it in custom UIViews to make it work on th iPhone. Does anyone know a way to enable drag interaction for custom UIViews for the iPhone?

谢谢

推荐答案

let dragInteraction: UIDragInteraction = ...
dragInteraction.isEnabled = true

view.addInteraction(dragInteraction)

检查一下

UIDragInteraction.isEnabledByDefault https://developer.apple.com/documentation/uikit/uidraginteraction/2891051-默认情况下启用

UIDragInteraction.isEnabledByDefault https://developer.apple.com/documentation/uikit/uidraginteraction/2891051-isenabledbydefault

这篇关于如何在iPhone的自定义UIViews上启用UIDragInteraction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆