xcode 是否可以在 Storyboard 中旋转图像,还是必须以编程方式进行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37282789/
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
Is it possible to rotate an image in Storyboard or do you have to do it programmatically?
提问by Crashalot
Assume you have a triangle image you want to use at different angles (e.g., 180 degrees, 90 degrees).
假设您有一个想要以不同角度(例如,180 度、90 度)使用的三角形图像。
Is it possible to rotate the triangle image within Storyboard, or do you need to do it programmatically?
是否可以在 Storyboard 中旋转三角形图像,还是需要以编程方式进行?
回答by Duncan C
You could probably create an IBDesignable
& IBInspectable
UIView
subclass that had a rotation angle property, and applied a transform to the image it contained.
您可能会创建一个具有旋转角度属性的IBDesignable
&IBInspectable
UIView
子类,并对它包含的图像应用变换。
IBInspectable
allows you to expose custom properties of your custom views in IB's Attributes inspector.
IBInspectable
允许您在 IB 的属性检查器中公开自定义视图的自定义属性。
Making a view IBDesignable
allows you to view a preview of your custom view object in IB.
创建视图IBDesignable
允许您在 IB 中查看自定义视图对象的预览。
回答by Vitalii
It is possible to set layer.transform.rotation.z
in User Defined Runtime Attributes. Check this answer: https://stackoverflow.com/a/32150954/2650588
可以layer.transform.rotation.z
在用户定义的运行时属性中进行设置。检查这个答案:https: //stackoverflow.com/a/32150954/2650588
回答by Alok
Programmatically some thing like this can help:
以编程方式,这样的事情可以提供帮助:
//rotate rect
myImageView.transform = CGAffineTransformMakeRotation(M_PI_2); //90 degree//rotation in radians
//For 180 degree use M_PI
Or make a macro like this:
或者做一个这样的宏:
#define DEGREES_TO_RADIANS(degree) (M_PI * (degree) / 180.0)
and use this way:
并使用这种方式:
CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));//here may be anything you want 45/90/180/270 etc.
More here : apple link
更多信息:苹果链接