[英]Rotate UIButton and preserve its size
我正在嘗試旋轉按鈕,形狀為正方形(65 x 65)。 旋轉后,按鈕會改變尺寸。 有沒有辦法,輪換並保持大小?
碼:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
self.stealthButton.transform = CGAffineTransformMakeRotation(radians);
self.recButton.transform = CGAffineTransformMakeRotation(radians);
self.toggleButton.transform = CGAffineTransformMakeRotation(radians);
[UIView commitAnimations];
嘗試這樣可能對你有幫助,
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 1;
fullRotation.repeatCount = 1;
[button.layer addAnimation:fullRotation forKey:@"360"];
在項目中添加以下框架。
#import <QuartzCore/QuartzCore.h>
#import "QuartzCore/CALayer.h"
它們不會改變它們的大小。 它們改變了框架的大小。
加:
CGFrame oldFrame = self.stealthButton.frame;
//Do that for all the buttons
//Do your rotation
self.stealthButton.frame = oldFrame;
但是:通過這樣做,您實際上會縮小按鈕的大小。 從用戶的角度來看,它會顯得更小。
確保將內容視圖設置為居中。
self.stealthButton.contentMode = UIViewContentModeCenter;
self.recButton.contentMode = UIViewContentModeCenter;
self.toggleButton.contentMode = UIViewContentModeCenter;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.