简体   繁体   English

使用动画将按钮旋转不到180度

[英]Rotating a button less than 180 degrees with animation

I'm trying to rotate a button when it is pressed by 45 degrees. 我试图将按钮按45度旋转。 The problem I have is that if the button is rotating 180 degrees it works fine, but if I choose an angle less than this the button still rotates but it jumps about the screen rather than rotating at its current location. 我的问题是,如果按钮旋转180度,效果很好,但是如果我选择一个小于此角度的按钮,按钮仍会旋转,但它会绕屏幕跳动而不是在当前位置旋转。 Is there any reason why this happens for angles less than 180 and how can I fix this? 有什么原因会导致角度小于180度,该如何解决?

This is the code I have. 这是我的代码。

Thanks 谢谢

- (void)viewDidLoad
{
angle = 45;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)Rotate:(id)sender {

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];


CGAffineTransform rotateTrans =
CGAffineTransformMakeRotation(angle * M_PI/180);


angle = angle + 45;

self.btnRotate.transform = rotateTrans;

[UIView commitAnimations];

}

I've discovered the problem was down to autolayout being used in interface builder. 我发现问题归结于在界面生成器中使用的自动布局。 Every time the object turned onto its side autolayout would reposition it on screen. 每次将对象转到其侧面时,自动布局都会在屏幕上重新定位它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM