1

I am trying to rotate buttons, that are shaped as a square (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];
4

3 回答 3

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"
于 2013-04-18T14:30:55.970 回答
0

他们不会改变他们的大小。他们改变框架的大小。

添加:

CGFrame oldFrame = self.stealthButton.frame;
//Do that for all the buttons
//Do your rotation
self.stealthButton.frame = oldFrame;

但是:这样做实际上会缩小按钮的大小。从用户的角度来看,它会显得更小。

于 2013-04-18T14:33:35.540 回答
0

确保您将内容视图设置为居中。

self.stealthButton.contentMode = UIViewContentModeCenter;
self.recButton.contentMode = UIViewContentModeCenter;
self.toggleButton.contentMode = UIViewContentModeCenter;
于 2013-04-18T14:42:59.763 回答