iPhone:重复转型
我试图表示一个在 iPhone 屏幕上旋转的视图。我有一个按钮,当你按下它时,视图会旋转 180 度。
我的问题是这仅在第一次有效。
代码如下:
-(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];
}
第一次单击时,视图旋转正常,但是当您再次单击时,什么也没有发生。没有错误,视图没有变化。
我缺少什么?
谢谢 贡索
I'm trying to represent a view that rotates on the iphone screen. I have a button and when you press it, the view rotates 180 degrees.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您基本上将两次变换设置为相同。在 else {} 语句中,使用:
transform = CGAffineTransformMakeRotation( RADIANS(0) );
事实上,您的代码不是采用 180 并添加 -180,而是采用 180 并将其设置为 -180。
You are basically setting the transform to be the same both times. In your else {} statement, use:
transform = 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.