- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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)
我也尝试用 mainView
替换 self.view.superview
但无济于事:
let window = UIWindow(frame: UIScreen.main.bounds)
let mainView = window.rootViewController?.view
我做错了什么以及如何在全局范围内跟踪拖动的图像?
最佳答案
为了实现这一目标,您必须遵循程序。
首先,当 panGesture
称为你必须创建一个 snapshot其中view/imageview
(无论如何)。
将该 snapsnot 添加为 self.view
的 subview (VC主视图)
要获取 View 相对于主视图的位置,您必须使用 convert(_:to:) 。现在根据此设置快照的帧。
您可以隐藏您的 view/imageview
在此之后,在用户交互中,看起来用户移动了相同的view/Imgview
.
现在匹配您的形象并做您想做的事情。
如果您想将该图像放在其原始空间,则当用户从 panGesture
结束时取消隐藏该图像。 .
希望现在您能更加清楚自己实际上必须做什么。
关于swift - UIPanGestureRecognizer 全局平移坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49936813/
UIGestureRecognizer 的文档引用重置函数。 但是,在 UIPanGestureRecognizer(UIGestureRecognizer 的子级)上调用 reset() 会生成此错
我有一个 UIPanGestureRecognizer,它根据我的喜好检测了太多次。我需要一个计数器并计算 3 个已完成的手势。每次我用手指平移识别器位置时,它都会触发 3 到 4 次。甚至触发了5个
我正在使用 UIPanGestureRecogniser实现拖放。当拖动开始时,我需要识别被拖动的对象。但是对象相对较小。如果用户没有在对象的中心点击对象,它就不会被拖动。 问题是当手势处理程序第一次
我正在尝试使用UIPanGestureRecognizer实现页面翻转动画。这是代码: - (void)handlePan:(UIPanGestureRecognizer *)recognizer {
我有一个 UIView 子类,我在其中添加了一个 UIPanGestureRocognizer: _panGestureRecognizer = [[UIPanGestureRecognizer al
我试图使用 UIPanGestureRecognizer 来移动我的对象,但我似乎无法让它顺利移动。当我朝一个特定的方向移动并转向相反的方向时,它不会立即使用react。我认为该值可能有问题,因为它在
我正在尝试实现 View 的拖动,当拖动停止时, View 滑到顶部并消失。我可以使用 UIPanGestureRecognizer 很好地拖动 View 。但在那之后,我用动画让它滑出。问题是在拖动
我在touchesEnded方法中调用了一个名为addProjectile的方法。 addProjectile接收touchesEnded方法接收的触摸的NSSet。为简单起见,我仅将相关代码发布到我
我遇到了 UIPanGestureRecognizer 的问题。假设我使用不同的标签动态添加 10 个按钮,当我添加第一个按钮时,尝试将其拖动到其他位置,然后它就可以正常工作。然后,如果我添加其他按钮
我有一个基类,它处理单元格的一些基本动画。在我的子类中,我已经覆盖了识别器目标并想做一些其他事情,但翻译始终是 0 因为我在基类中调用翻译被重置为 .zero . 有没有办法让我的基类执行基本动画并使
我正在使用 UIPanGestureRecognizer 将图像拖出 UICollectionViewCell,然后查看它是否与屏幕上其他位置的另一个图像发生碰撞。为此,我需要能够匹配他们的翻译坐标。
我创建了一个UIPanGestureRecognizer,但问题是当我将 View 向右滑动时, View 会向左移动。 当我向左滑动 View 时,它会向右滑动。为什么? let panGestur
我正在开发一个类似于 Tinder 中的卡片 View 。当卡片X原点大于我声明的值时,它会移出屏幕。否则,它会再次粘在中心。我正在 UIPanGestureRecognizer 函数中执行所有这些操
我有一个 UIPanGestureRecognizer 附加到父 View ,带有各种 CCSprite 我想在平移时在父 View 中移动。使用 [gesture locationOfTouch:i
使用 UIPanGestureRecognizer 我们正在移动 UICollectionView 中的单元格 当我们开始拖动时 UIGestureRecognizerStateBegan 被调用。但
我有 6 个 UIImageView,每个都连接到 UIPanGestureRecognizer,它们都连接到相同的方法。方法是: - (IBAction)handlePan:(UIPanGestur
我是 swift 和 xcode 的新手。使用 xcode 10 并尝试制作一个类似应用程序的嗡嗡声,我需要在 View 中移动多个图像。我发现了很多关于 UIPanGestureRecognizer
我有一个侧面板,其中有一个 UIImageView,我在其中附加了一个 UIPanGestureRecognizer,以便您可以推/拉侧边栏。效果很好。 问题是我有一些按钮有时会出现在侧边栏下方。如果
本质上,我想做的是移动 View 以跟随用户的平移。只要使用相同的平移对象,这种方法就可以正常工作。当用户释放并启动另一个平移时,问题就出现了。 根据文档,translationInView 中的值是
我正在将 UIPanGestureRecognizer 添加到我的 View Controller 中的一个自定义 View 。 我还使用 MFSideMenu 作为滑动菜单,在其框架中将 UIPan
我是一名优秀的程序员,十分优秀!