编写一个循环 UIGestureRecognizer

发布于 2024-09-08 11:57:00 字数 138 浏览 1 评论 0原文

我正在寻找在 iPhone / iPad 应用程序中创建一个缓动轮。我知道您可以子类化 UIGestureRecognizer 来编写自己的识别器。有谁知道如何(主要是其背后的数学原理)创建一个可以检测圆形运动的运动,也许与平移手势相结合?

谢谢

I'm looking to create a jog wheel in an iPhone / iPad application. I know that you can subclass UIGestureRecognizer to write your own recognizers. Does anyone know how (mainly the maths behind it) to create one that would detect a circular movement, perhaps in combination with a pan gesture?

Thanks

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

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

发布评论

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

评论(1

油焖大侠 2024-09-15 11:57:00

这个问题并不容易。我花了一些时间思考可能的解决方案:
我认为您需要的是必须设置的一些关键属性:

  • 圆形运动的中心(在这种情况下没有问题,因为您知道缓动轮的中心)
  • 应该发生运动的走廊。
    • 所以您需要内半径和外半径。

现在你有这样的东西(不幸的是我没有足够的声誉,所以只有链接: http://img17.imageshack.us/img17/4416/bildschirmfoto20100721u.png

现在开始计算背后的数学:
首先,您将走廊分为四个部分:

  • 从 0° 到 90°
  • 从 90° 到 180°
  • 从 180° 到 270°
  • 从 270° 到 360°

对于每个季度,您必须弄清楚手指何时移动(让我们假设 0° 线是从中心点直线到顶部):

  • 如果手指位于第一四分之一,您就知道 x 是否向左变化,则旋转必须是逆时针的。如果 x 向右变化,则旋转必须是顺时针方向。

将这个逻辑应用到所有季度。现在您知道缓动轮是顺时针还是逆时针移动。你必须确保手指永远不会离开走廊(如果你测试这个逻辑并且运动因为离开走廊而停止,则使走廊更大 - 感谢 CrystalSkull 的评论:使用 44px 作为最小宽度走廊适用于人机界面指南)。

总结
所以现在您可以得出结论,您需要一个中心点和一个手指可以移动的走廊。
您必须弄清楚手指位于哪四分之一,并找出(使用 x 值)旋转是顺时针还是逆时针。

我希望这对你有一点帮助。

this question isn't easy. I spend some time thinking of a possible solution:
I think what you need are some key properties you have to set:

  • The center of the circular movement (in this case no problem, because you know the center of the jog wheel)
  • A corridor in which the movement should happen.
    • so you need the inner radius and the outer radius.

Now you have something like this (unfortunately I haven't got enough reputation so only the link: http://img17.imageshack.us/img17/4416/bildschirmfoto20100721u.png

Now the maths behind this starts:
First of all you arrange the corridor in four quarters:

  • From 0° to 90°
  • From 90° to 180°
  • From 180° to 270°
  • From 270° to 360°

For each quarter you have to figure out when the finger is moving (let's say that the 0°-line is from the center point straight to the top):

  • if the finger is in the first quarter you know if the x changes to the left that the rotation must be anti-clockwise. If the x changes to the right the rotation must be clockwise.

Apply this logic for all quarters. Now you know if the jog wheel is moved clockwise or anti-clockwise. You have to make sure, that the finger is never leaving the corridor (if you test this logic and the movement stops because of leaving the corridor, make the corridor bigger - Thanks to CrystalSkull for his comment: Use 44px as a minimum width for the corridor to apply to the Human Interface Guidelines).

Sumary
So now you can conclude that you need a center point and a corridor the finger can move in.
You have to figure out in which quarter the finger is in and find out (using the x-value) if the rotation is clockwise or anti-clockwise.

I hope this helps you a little bit.

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