【发布时间】:2009-07-29 19:19:55
【问题描述】:
我需要在 iphone sdk interface builder 中将一个按钮旋转 30 度,你是怎么做的?
【问题讨论】:
我需要在 iphone sdk interface builder 中将一个按钮旋转 30 度,你是怎么做的?
【问题讨论】:
您无法在 Interface Builder 中执行此操作,但代码非常简单。
确保您已将 IB 中的按钮连接到类型为 UIButton* 的 IBOutlet(我们称之为 myButton)。然后一旦 nib 被加载(例如,在你的 viewDidLoad 方法中)你可以使用这样的东西:
#define RADIANS(degrees) ((degrees * M_PI) / 180.0)
CGAffineTransform rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity,
RADIANS(30.0));
myButton.transform = rotateTransform;
【讨论】:
我不确定您是否可以直接执行此操作。如果您通过 CoreGraphics 图层绘制自己的按钮,您也许可以做到这一点。
【讨论】:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
button.transform=CGAffineTransformMakeRotation((0.0174532925)*30);
//put the -ve sign before 30 if you want to rotate the button in the anticlockwise else use this one
[UIView commitAnimations];
【讨论】: