为响应触摸事件的旋转轮设置动画的最佳方式
我需要指导来找到正确的方向。 我想构建一个旋转轮控件,用户可以在其中选择一个元素。
我想完成以下任务:
- 接收触摸事件,该事件将根据 TouchMoved 中的手指位置旋转滚轮
- 当所选图像指示器通过时放大所选图像指示器内部的图像。
我正在考虑核心动画基本动画和旋转动画。 使用动画组并旋转它。
问题一: 如何将动画同步到触摸事件。
问题2: 我如何知道哪张图像是我需要放大的图像,例如 CGAffineTransformMakeScale。
对于我的问题有最佳实践吗?特别是。考虑到性能?
I need guidance towards the right direction to take here.
I want to build a spinning wheel control where a user can select an element.
I want to accomplish the following:
- Receive touch events that will rotate the wheel based on the finger position in touchesMoved
- Magnify the image that is inside the selected image indicator when it passes through.
I was thinking of a core animation Basic Animation and animating the rotation.
Using an animation group and rotate it around.
Problem 1:
How do I sync the animation to the touch events.
Problem 2:
How will I know which image is the one I need to magnify with for example an CGAffineTransformMakeScale.
Is there a best practice for my problem. Esp. with performance in mind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过更新每个触摸移动事件的滚轮来实现此目的。
对于每个 touchmoved、touchbegin 事件,您都可以知道从滚轮中心到手指的连线的角度。您保存开始角度,然后您就会知道差异角度。轮子可以根据您的手指使用角度进行旋转。
您可以通过这两种方式之一来放大图像图标。
1.您可以知道所有轮盘中图像图标的角度,并且您还可以知道轮盘当前的角度。所以,如果图像图标是在直角之间。前任。如果滚轮位于 45 度,则 -45 度或 360-45 度的图标将会放大。
2. 检查每个图像图标的 y 原点,如果图像图标原点 y 高于阈值。
You can achieve this by update the wheel for every touchmoved event.
For each touchmoved, touchbegin event, you can know the angle of the line from center of the wheel to your finger. You save your begin angle, then you will know the diff angle. The wheel can rotate depends on your finger by using angle.
you can enlarge the image icon by either of these two ways.
1. You can know which image icon angle in all the wheel, and you also know current angle of the wheel. So, if the image icon is between the right angle. Ex. if wheel is at 45 degree, then icon at -45 or 360-45 degree will be enlarged.
2. check the y origin of each image icon, if the image icon origin y is above threshold.