[英]iphone: repeating a transformation
I'm trying to represent a view that rotates on the iphone screen. 我试图代表一个在iPhone屏幕上旋转的视图。 I have a button and when you press it, the view rotates 180 degrees.
我有一个按钮,当您按下它时,视图旋转180度。
My problem is that this only works the first time. 我的问题是,这只能在第一次使用。
Here is the code: 这是代码:
-(IBAction) flip:(id)sender{
CGAffineTransform transform; //the transform matrix to be used below
//BEGIN ANIMATIONS
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
//animate
if (flag){
transform = CGAffineTransformMakeRotation( RADIANS(180) );
} else {
transform = CGAffineTransformMakeRotation( RADIANS(-180) );
}
flag = !flag;
transform = CGAffineTransformTranslate(transform, 0, 0);
self.mySuview.transform = transform;
//COMMIT ANIMATIONS
[UIView commitAnimations];
}
The first time you click, the view spins alright, but when you click again NOTHING happens. 当您第一次单击,视图旋转好了,但是当你再次单击什么也不会发生。 No errors, no changes on the view.
没有错误,视图上没有更改。
What am I missing? 我想念什么?
Thanks Gonso 谢谢贡索
You are basically setting the transform to be the same both times. 您基本上将转换设置为两次都相同。 In your else {} statement, use:
在您的else {}语句中,使用:
transform = CGAffineTransformMakeRotation( RADIANS(0) ); 变换= CGAffineTransformMakeRotation(RADIANS(0));
As is, your code is not taking the 180 and adding -180, it's taking the 180 and setting it to -180. 照原样,您的代码不是采用180并加上-180,而是采用180并将其设置为-180。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.