【问题标题】:Scale/Rotate a button in interface缩放/旋转界面中的按钮
【发布时间】:2009-07-29 19:19:55
【问题描述】:

我需要在 iphone sdk interface builder 中将一个按钮旋转 30 度,你是怎么做的?

【问题讨论】:

标签: iphone button rotation


【解决方案1】:

您无法在 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;

【讨论】:

    【解决方案2】:

    我不确定您是否可以直接执行此操作。如果您通过 CoreGraphics 图层绘制自己的按钮,您也许可以做到这一点。

    Core Animation Layers

    【讨论】:

      【解决方案3】:
                   [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];
      

      【讨论】:

        猜你喜欢
        • 2023-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多