1

我想旋转按钮,形状为一个正方形(65 x 65)。旋转它们后,按钮会改变它们的大小。有什么办法,做一个轮换和保持大小?旋转UIButton并保留其大小

代码:

[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

是否要在转换后将它们调整到原始大小?因为它必须缩放以适合原始尺寸 – Ossir

回答

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" 
+0

@Michal:你有答案吗? – Balu

+0

Pefect解决方案时+ UIView:animateWithDuration:与自动布局不工作预期! – Nianliang

0

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

地址:

但是:这样你会真正缩小按钮的大小。从用户的角度来看,它会显得小得多。

0

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

self.stealthButton.contentMode = UIViewContentModeCenter; 
self.recButton.contentMode = UIViewContentModeCenter; 
self.toggleButton.contentMode = UIViewContentModeCenter;