我正在尝试旋转按钮,形状为正方形(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];
答案 0 :(得分:3)
尝试这样可能对你有帮助,
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"
答案 1 :(得分:0)
它们不会改变它们的大小。它们改变了框架的大小。
添加:
CGFrame oldFrame = self.stealthButton.frame;
//Do that for all the buttons
//Do your rotation
self.stealthButton.frame = oldFrame;
但是:通过这样做,你实际上会缩小按钮的大小。从用户的角度来看,它会显得更小。
答案 2 :(得分:0)
确保将内容视图设置为居中。
self.stealthButton.contentMode = UIViewContentModeCenter;
self.recButton.contentMode = UIViewContentModeCenter;
self.toggleButton.contentMode = UIViewContentModeCenter;