xcode 如何旋转 UIImageView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6319906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:14:51  来源:igfitidea点击:

How to rotate a UIImageView

iphonexcodeuiimageviewrotationspinning

提问by Blane Townsend

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.

我有一个 UIImageView 是星星的图像。问题是我希望星星在移动时旋转。如何旋转 UIImageView 以使其看起来像是在旋转 3 秒。我想让它旋转 720 度。

回答by PengOne

For a very simple approach, you can use

对于一个非常简单的方法,您可以使用

imageView.transform = CGAffineTransformMakeRotation(radianRotation);

where radianRotationis a float, e.g. 4*pi for 720 degrees. You can play with basic animations and changing the rotation however you like.

哪里radianRotation是浮点数,例如 4*pi 表示 720 度。您可以玩基本的动画并根据需要更改旋转。

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?

但是,如果您想要一个更复杂的解决方案,那么我强烈建议您查看此相关帖子的答案:如何使用固定点旋转 UIIMageVIew?

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).

此外,请参阅屏幕右侧链接的无数相关帖子。许多都有你需要的所有代码(除非绕圈子两次)。

回答by iWheelBuy

You can also use

你也可以使用

[imageView layer].transform = CATransform3DMakeRotation(variables);

回答by Juanma Reyes

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.

对于您的商品,除了 PengOne 的回答之外,您还可以使用 math.h 中可用的 M_PI、M_PI_2、M_PI_4 常量。