How can I rotate an UIImageView in Interface Builder?

本小妞迷上赌 提交于 2019-12-10 13:25:38

问题


Is it possible to rotate an UIImageView in Interface Builder from XCode? Like I can do it in Photoshop, where I can scale and rotate an image.

I know it is possible by code but is there a way to do this in the interface builder?


回答1:


You can't do this in the current version of Xcode. You may submit a feature request to Apple at http://radar.apple.com

However if you want to do it, you will need to write some code

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)

theView.transform = CGAffineTransformRotate(theView.transform, radians)



回答2:


Yes, you can do this in interface builder without any additional code with layer.transform.rotation.z runtime attribute. Note that this value is in radians.




回答3:


Yes you can but using a little trick.

Declare in your code a new UIView Category like this

@interface UIView (IBRotateView)

@property (nonatomic, assign) CGFloat rotation;

@end


@implementation UIView (IBRotateView)
@dynamic rotation;

- (void)setRotation:(CGFloat)deg
{
    CGFloat rad = M_PI * deg / 180.0;

    CGAffineTransform rot = CGAffineTransformMakeRotation(rad);

    [self setTransform:rot];
}

@end

Now you can use a runtime parameter "rotation" directly on interface builder like this on any UIView you like.

Obviously interface builder will not rotate the view in its internal render because it will only effect the runtime rendering.




回答4:


Nope thats not possible in the interface builder but the code is quite simple:

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)

CGAffineTransform rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity,
     RADIANS(120.0));

imageView.transform = rotateTransform;


来源:https://stackoverflow.com/questions/14654096/how-can-i-rotate-an-uiimageview-in-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!