如何旋转 UIImageView
我有一个 UIImageView,它是星星的图像。问题是我希望星星在移动时旋转。如何旋转 UIImageView 使其看起来像旋转 3 秒。我想让它旋转 720 度。
I have a UIImageView that is an image of the star. The problem is I want the star to rotate when I move it. How can I rotate a UIImageView to make it look like it is spinning for 3 seconds. I want it to spin 720 degrees.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于非常简单的方法,您可以使用
其中
radianRotation
是浮点数,例如 4*pi 表示 720 度。您可以使用基本动画并根据需要更改旋转。但是,如果您想要更复杂的解决方案,那么我强烈建议您查看此相关帖子的答案:如何使用固定点旋转 UIIMageVIew?
另外,请参阅屏幕右侧链接的无数相关帖子。许多人都有你需要的所有代码(除非绕圈两次)。
For a very simple approach, you can use
where
radianRotation
is a float, e.g. 4*pi for 720 degrees. You can play with basic animations and changing the rotation however you like.However, if you want a more sophisticated solution, then I highly recommend you look at the answers to this related post: how to rotate UIIMageVIew with fix point?
Also, see the myriad related posts linked on the right hand side of your screen. Many have all the code you need (barring going around in a circle twice).
您还可以使用
You can also use
对于您的商品,除了 PengOne 的答案之外,您还可以使用 math.h 中提供的 M_PI、M_PI_2、M_PI_4 常量。
For your commodity, additionally to PengOne's answer you can use M_PI, M_PI_2, M_PI_4 constants that are available in math.h.