自动旋转和 UIImageView 动画的问题
我定期旋转 UIImageView 。我的视图非常基本,是 UITabBar 视图集中的视图。如果我在旋转动画时碰巧旋转了 iPad,那么我的图像就会倾斜。我已经在我的 xib 文件中检查了我能想到的所有图像,自动调整大小已完全关闭,并且我不会在父视图上自动调整子视图的大小。
这是我的动画代码:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
transform = CGAffineTransformMakeRotation(convertToRadian(myDegrees));
myImage.transform = transform;
[UIView commitAnimations];
如果我取出动画,那么一切都会按我的预期进行。如果我不旋转我的设备,此旋转代码似乎工作正常。
我该怎么做才能防止内置旋转动画改变我的动画和倾斜我的图像?
I am rotating a UIImageView in place periodically. My view is very basic, a view inside of a UITabBar view set. If I happen to rotate my iPad while my rotation is animating then my image becomes skewed. 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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过多次不同的尝试后,我最终在这里做的是添加一个清晰的视图,其中包含旋转图像,并在界面生成器中将“自动调整大小子视图”设置为关闭。您也可以根据需要在代码中执行此操作。我必须添加 UIView 占位符,因为包含旋转图像的超级视图需要在旋转时自动调整其他视图对象的大小,但这解决了由于方向变化动画与手动旋转动画同时发生的图像倾斜问题就位。
希望这对某人有帮助。
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.
Hope this helps someone.
坐标系发生变化。我也想出了这么多...以为我有一个错误。如果保存 CG ... GState,则可以恢复到最初使用的坐标系。这是戴特尔和戴特尔的书中的内容。我刚刚找到了。想将其发布给也正在寻找的人。
不过你有一个聪明的伎俩!如果这不起作用,我可能会使用它。
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. This is in Deitel and Deitel's book. 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.