【发布时间】:2018-04-20 16:24:40
【问题描述】:
我正在使用UIPanGestureRecognizer 将图像拖出UICollectionViewCell,然后查看它是否与屏幕上其他位置的另一个图像发生冲突。
为此,我需要能够匹配他们的翻译坐标。我的理解是,由于图像位于 collectionView 单元格内,因此它被跟踪相对单元格坐标,我需要成为全局跟踪器。
|---------------------------------------|
| _______ |
| |_image_| |
| |
|---------------------------------------|
| |image| Collection View |
|---------------------------------------|
到目前为止,当我将图像拖到另一个图像上时,我将其作为日志:
moved imageView center: (-44.0, -143.5)
destination imageView center: (440.0, 175.0)
let translation = panGesture.translation(in: self.view.superview)
self.view.center = CGPoint(x: self.initialLocation.x + translation.x, y: self.initialLocation.y + translation.y)
我也尝试将self.view.superview 替换为mainView,但无济于事:
let window = UIWindow(frame: UIScreen.main.bounds)
let mainView = window.rootViewController?.view
我做错了什么,如何在全局范围内跟踪拖动的图像?
【问题讨论】:
标签: swift uigesturerecognizer uipangesturerecognizer