iphone - 当我在 CGAffineTransformMakeScale 动画中设置 UIImageView 的框架时出现奇怪的行为

发布于 2024-11-26 10:58:29 字数 808 浏览 1 评论 0原文

我有一个 UIImageView 显示带有 UIViewContentModeScaleAspectFill 的 contentMode 的图像。

然后我将 CGAffineTransformMakeScale 的动画(大约 30 秒)与 UIImageView 关联起来。

imageView.transform = CGAffineTransformMakeScale(1,1);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:30];
imageView.transform = CGAffineTransformMakeScale(1.9,1.9);
[UIView commitAnimations];

30秒后,当一轮动画完成时,我将向imageView设置另一个图像并重新启动动画。

一切都很好。但是当我尝试旋转 UIImageView 以适应用户对设备方向的选择时,它变得有线。

当用户要更改方向时,我将 UIImageView 的框架相应地设置为 CGRectMake(0, 0, 768, 1004) 或 CGRectMake (0, 0, 1024, 748)。

奇怪的是:

如果UIImageView的frame在动画的时候改变了,也没有问题。但是当下一个图像到来并开始新一轮动画时,UIImageView突然在屏幕中心变小(应该是全屏),然后放大动画照常开始,只是不再全屏了。

谁能告诉我如何在 UIImageView 进行变换时控制框架或方向?

因为我猜这就是出错的地方。

谢谢

I have a UIImageView showing an image with the contentMode of UIViewContentModeScaleAspectFill.

Then I am associating a animation (about 30 seconds) of CGAffineTransformMakeScale with the UIImageView.

imageView.transform = CGAffineTransformMakeScale(1,1);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:30];
imageView.transform = CGAffineTransformMakeScale(1.9,1.9);
[UIView commitAnimations];

After 30 seconds, when a round of animation is done, I will set another image to the imageView and restart the animation.

Everything is fine. But when I try to rotate the UIImageView to adapt user's selection of device orientation, it becomes wired.

When the user is about to change the orientation, I set the UIImageView's frame to CGRectMake(0, 0, 768, 1004) or CGRectMake (0, 0, 1024, 748), accordingly.

The strange thing is:

if the frame of UIImageView is changed while the animation, it is fine. But when the next image comes and starts a new round of animation, the UIImageView suddenly became small in the center of screen (is supposed to be full screen) and then the animation of zoom-in started as usual, just not full screen any more.

Can anyone tell me how to control the frame or orientation while the UIImageView has a transform with it?

Because I guess this is where it went wrong.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝天 2024-12-03 10:58:29

引用 frame 属性的文档

警告:如果变换属性不是恒等变换,则该属性的值未定义,因此应被忽略。

如果您正在使用转换,您可能应该弄乱 centerbounds

Quoth the documentation for the frame property:

Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.

You should probably be messing with center and bounds instead, if you are using transformations.

花辞树 2024-12-03 10:58:29

变换时未定义框架属性。在这种情况下,使用边界而不是框架。

Frame property is not defined when transforming. Use bounds instead of frame in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文