简体   繁体   English

自动旋转和UIImageView动画的问题

[英]Problems with auto-rotation and UIImageView animations

I am rotating a UIImageView in place periodically. 我定期旋转UIImageView。 My view is very basic, a view inside of a UITabBar view set. 我的视图非常基本,是UITabBar视图集中的视图。 If I happen to rotate my iPad while my rotation is animating then my image becomes skewed. 如果在旋转动画时恰好旋转iPad,那么我的图像就会歪斜。 I have checked everything I can think of in my xib file for my image, the autoresizing is turned completely off and I am not auto-resizing subviews on the parent view. 我已经检查了我在xib文件中可以想到的所有内容,自动调整大小功能已完全关闭,并且我没有在父视图上自动调整子视图的大小。

Here is my animation code: 这是我的动画代码:

            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.5];
            [UIView setAnimationDelay:0.0];
            transform = CGAffineTransformMakeRotation(convertToRadian(myDegrees));
            myImage.transform = transform;  
            [UIView commitAnimations];

If I take my animation out then everything works as I would expect. 如果我取出动画,那么一切都会按预期进行。 This rotation code appears to work fine if I do not rotate my device. 如果不旋转设备,此旋转代码似乎可以正常工作。

What can I do to keep the built-in rotation animation from altering my animation and skewing my images? 如何防止内置旋转动画改变动画和使图像倾斜?

After many different attempts, what I ended up doing here is adding a clear view with my rotating images inside of it and setting the "auto-resize sub views" to off in interface builder. 经过许多不同的尝试,我最终在此处所做的是添加一个清晰的视图,其中包含旋转图像,并在界面构建器中将“自动调整子视图”设置为关闭。 You can also do this in code as needed. 您也可以根据需要在代码中执行此操作。 I had to add the UIView placeholder because the super view containing my rotating images needed to auto-resize other view objects on rotation, but this fixed the funky skewing of my images due to animation of orientation change at the same time as animating a manual rotation in place. 我必须添加UIView占位符,因为包含旋转图像的超级视图需要在旋转时自动调整其他视图对象的大小,但是由于固定了动画方向的动画,这固定了我的图像的歪斜,这是因为方向改变的动画到位。

Hope this helps someone. 希望这对某人有帮助。

The coordinate system gets changed. 坐标系被更改。 I've figured this much out too... thought I had a bug. 我也已经弄清楚了...以为我有一个错误。 If you save the CG ... GState, then you can revert back to the coordinate system initially used. 如果保存CG ... GState,则可以还原为最初使用的坐标系。 This is in Deitel and Deitel's book. 这是在Deitel和Deitel的书中。 I just found it. 我刚刚找到了。 Wanted to post it for anyone also looking. 想要将其发布给也正在寻找的任何人。

You got a clever trick though! 你有个聪明的把戏! I might use it if this won't work. 如果无法使用,我可能会使用它。

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

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