iOS - 使用 UIPanGestureRecognizer 平移时实时推进动画
基本上我想复制地球的旋转。
在现实世界中,您将手指放在地球仪上,然后将其向右移动,当您移动手指时,地球仪向右旋转。
在 iPhone 上,事情没那么简单……
可能很简单,比如一根手指放在屏幕上,X 点被抓住,然后当手指向右移动一个像素时,地球仪向右旋转一帧,然后原点更改为新地点。然后,如果手指移回原来的位置,地球仪就会向左旋转一帧。一切都不需要拿起你的手指...
那么我该怎么办呢?我假设有一个“whileTouching”事件会持续运行/每 500 毫秒/等等...
有人知道这样的示例代码吗?
编辑:前进框架本身我只能管理捕获我无法弄清楚的触摸事件。
Basically I want to replicate the spinning of a globe.
In the real world you'd put your finger on the globe and and move it to the right and while you are moving your finger the globe spins to the right.
On an iPhone it's not that simple...
It could be something as simple as a finger comes down on the screen and point X is grabbed and then when the finger moves one pixel to the right the globe spines one frame to the right and the origin changes to the new spot. Then if the finger moves back to the original spot the globe spin one frame to the left. All with out picking up your finger...
So how might I go about this? I assume there is a "whileTouching" event that would run constantly / every 500ms / etc...
Anyone know of some sample code like this?
Edit: The advancing the frame itself I can manage just the capturing of the touch event I can't figure out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每当手指移动时,UIPanGestureRecognizer 将继续调用其操作方法。您使用状态来确定如何更改当前视图。
此代码示例假设视图的视图控制器处理手势。
The UIPanGestureRecognizer will continue to call its action methods whenever the finger moves. You use the state to determine how to change the current view.
This code sample assumes that the view's view controller handles the gesture.
听起来您应该使用 UIPanGestureRecognizer 来执行此操作。基本上,只要您的手指被按下,这就会跟踪您的手指按压,并在特定视图内进行翻译。
编码的简要想法如下:
这会将手势识别器添加到您的视图中(假设此代码位于视图控制器中)。然后,您需要在函数“someFunction”中添加“globe spin”代码。
像这样的事情:
[recognizer TranslationInView:self.view] 将为您提供手势识别器的翻译。您可以使用它来设置地球的图像或变换,但您正在处理实际的旋转。
希望这有帮助。
干杯。
It sounds like you should use a UIPanGestureRecognizer to do this. Basically this will track your finger press and it's translation within a specific view as long as your finger is pressed.
A brief idea for the coding would be something like:
This will add the gesture recognizer to your view (assuming this code is in a view controller). Then you would need to add the "globe spinning" code inside the function "someFunction".
Something like this:
The [recognizer translationInView:self.view] will give you the translation of your gesture recognizer. You can use this to set the image or transform of your globe, however you are dealing with the actual spinning.
Hope this helps.
Cheers.