[英]Rotate UIButton and preserve its size
I am trying to rotate buttons, that are shaped as a square (65 x 65). 我正在尝试旋转按钮,形状为正方形(65 x 65)。 After I rotate them, the buttons change their sizes. 旋转后,按钮会改变尺寸。 Is there any way, to make a rotation and keep the size? 有没有办法,轮换并保持大小?
Code: 码:
[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];
try like this may be it helps you , 尝试这样可能对你有帮助,
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"];
Add below framework in your project. 在项目中添加以下框架。
#import <QuartzCore/QuartzCore.h>
#import "QuartzCore/CALayer.h"
They don't change their size. 它们不会改变它们的大小。 They change the frame's size. 它们改变了框架的大小。
Add: 加:
CGFrame oldFrame = self.stealthButton.frame;
//Do that for all the buttons
//Do your rotation
self.stealthButton.frame = oldFrame;
BUT: By doing so you will actually shrink the button's size. 但是:通过这样做,您实际上会缩小按钮的大小。 From the user's point of view it will appear much smaller. 从用户的角度来看,它会显得更小。
Make sure that you have the content view set to center. 确保将内容视图设置为居中。
self.stealthButton.contentMode = UIViewContentModeCenter;
self.recButton.contentMode = UIViewContentModeCenter;
self.toggleButton.contentMode = UIViewContentModeCenter;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.