How to enable UIDragInteraction on Custom UIViews for iPhone

你离开我真会死。 提交于 2019-12-13 15:18:07

问题


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.

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

collectionView.dragInteractionEnabled = true tableView.dragInteractionEnabled = true

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?

Thanks


回答1:


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

view.addInteraction(dragInteraction)

Check this out

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



来源:https://stackoverflow.com/questions/45225329/how-to-enable-uidraginteraction-on-custom-uiviews-for-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!