编写一个循环 UIGestureRecognizer
我正在寻找在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题并不容易。我花了一些时间思考可能的解决方案:
我认为您需要的是必须设置的一些关键属性:
现在你有这样的东西(不幸的是我没有足够的声誉,所以只有链接: http://img17.imageshack.us/img17/4416/bildschirmfoto20100721u.png
现在开始计算背后的数学:
首先,您将走廊分为四个部分:
对于每个季度,您必须弄清楚手指何时移动(让我们假设 0° 线是从中心点直线到顶部):
将这个逻辑应用到所有季度。现在您知道缓动轮是顺时针还是逆时针移动。你必须确保手指永远不会离开走廊(如果你测试这个逻辑并且运动因为离开走廊而停止,则使走廊更大 - 感谢 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:
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:
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):
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.