簡體   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