[英]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.