使用 UIGestureRecognizer 沿 x 轴移动 UIImageView

发布于 2024-09-28 16:25:19 字数 179 浏览 6 评论 0原文

我有四个 UIImageView 排成一排,我希望能够从左到右移动图像。有没有办法将运动绑定到 x 轴(沿着图像中心),即仅向左和向右移动它们?类似于在 iPhone 屏幕上移动图标。

我向每个视图添加了一个 UIPanGestureRecognizer,这使我可以将它们移动到屏幕上的任何位置。

有什么想法吗?

I have four UIImageViews lined up in a row and I want to be able to move the images from left to right. Is there a way to bound the movement to the x-axis (along the image centers) i.e. moving them only left and right? Similar to moving the icons around the screens on an iPhone.

I've added a UIPanGestureRecognizer to each of the views which allows me to move them around everywhere on the screen.

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撕心裂肺的伤痛 2024-10-05 16:25:19

好吧,如果您不想在 y 轴上移动,请不要修改 y 轴。只需根据手势识别器的移动更改 x 坐标即可。到底是什么问题呢?

Well, if you don't want movement on the y axis, don't modify the y axis. Just change the x coordindate according to the gesture recognizer's movement. What exactly is the problem?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文