繁体   English   中英

改变方向旋转UIButton

[英]Rotate UIButton on change of orientation

我有一个圆形按钮,包含以下图像

现在,在设备旋转时,我想以使图像保持方向的方式旋转按钮。

我该如何做到这一点,

我不想更改按钮的框架,我希望它保持原样,我只想转换按钮。

如果您有IBOutlet对象。

theButton.transform = CGAffineTransformMakeRotation(M_PI / -4);

如果要在视图上创建运行时按钮。

- (void)viewDidLoad {
  [super viewDidLoad];
  UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
  [btn setFrame:CGRectMake(100, 100, 200, 44)];
  btn.transform=CGAffineTransformMakeRotation(M_PI / -4);
  [btn setTitle:@"RakeshBhatt" forState:UIControlStateNormal];
  [self.view addSubview:btn];
}

要旋转图像视图,请尝试以下操作

// Set the anchor point and center so the view swings from the upper right
imageView.layer.anchorPoint = CGPointMake(1.0, 0.0);
imageView.center = CGPointMake(CGRectGetWidth(self.view.bounds), 0.0);

// Rotate 90 degrees to hide it off screen
CGAffineTransform rotationTransform = CGAffineTransformIdentity;
rotationTransform = CGAffineTransformRotate(rotationTransform, DegreesToRadians(90));
swingView.transform = rotationTransform;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM