iPhone - 如何建立状轮轮盘​​赌? [英] iPhone - How to build a roulette like wheel?

查看:216
本文介绍了iPhone - 如何建立状轮轮盘​​赌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找一个教程或你将如何建立一个纺轮,可以用手指两个方向进行旋转和捕捉到的特定点任何暗示。我已经调查基本的动画,但停留在用户交互的一面。

I'm looking for a tutorial or any hint on how you would build a spinning wheel that can be rotated in both directions with your finger and snaps to specific points. I have looked into basic animations but stuck on the user interaction side.

任何暗示是非常AP preciated。

Any hint is highly appreciated.

推荐答案

从根本上说,你只需要执行一个的UIImageView ,其中旋转角度是由控制的旋转变换跟踪你的手指。我贴这个的一个片段<一个href=\"http://stackoverflow.com/questions/3725818/objective-c-rotate-wheel-using-radians/3735140#3735140\">similar问题。

Fundamentally you just need to perform a rotate transform on a UIImageView where the angle of rotation is controlled by tracking your finger. I posted a snippet about this for similar question.

概括地说, ATAN2()会给你从轮图像的指定中心的矢量角,因此对于(x,y)的一个的触摸事件,当前角度是 ATAN2(Y-CY,X-CX)其中(CX,CY)是车轮的中心。跟踪这个角度增量的变化,所以你知道多少当用户的手指移动到转动车轮。

Broadly, atan2() will give you the vector angle from the designated centre of the wheel image, so for a touch event at (x,y), the current angle would be atan2(y-cy,x-cx) where (cx,cy) is the centre of the wheel. Track changes in this angle for the delta, so you know how much to rotate the wheel by when the user's finger moves.

捕捉在其最简单的棘轮效应车轮需要直到它超过一个特定的阈值被钳位为零增量角度。当然,如果你想要的棘轮效应看起来非常逼真,在适当的加速和减速,这是另一个问题,您应该咨询一个很好的物理书或网站。

Snapping the wheel for a ratchet effect at its simplest requires the delta angle to be clamped to zero until it exceeds a certain threshold. Of course, if you want the ratchet effect to look very realistic, with proper acceleration and deceleration, that's another matter and you should consult a good physics book or website.

这篇关于iPhone - 如何建立状轮轮盘​​赌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆