我正在尝试旋转形状为正方形(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"
关于ios - 旋转UIButton并保留其大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16085651/