更改设备旋转时的 iPhone 背景图像

发布于 2024-11-18 00:56:47 字数 215 浏览 2 评论 0原文

我有一个 UIImageView 作为控件后面的背景,旋转设备时出现问题。我想根据方向使用不同的图像

那么处理这个问题的最佳方法是什么? 添加和删​​除横向和纵向的每个 UIImageView? 将两者都放在视图上并隐藏/显示适当的一个? 或者也许有一些类或 UIObject 来处理这个问题?

TIA

I have an UIImageView as a background behind my controls, the problem comes when rotating the device. I'd like to use a different image depending on the orientation.

So what would be the best way to handle that?
Adding and removing each UIImageView for landscape and portrait?
Having both on the view and hide/show the appropriate one?
Or maybe there is some class or UIObject for handling that?

TIA

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

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

发布评论

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

评论(3

寄离 2024-11-25 00:56:47

您可以使用它,将两张背景图像叠加在一起,一张的 alpha = 1.0,另一张的 alpha = 0.0。然后,当您旋转时,使用动画将 alpha 分别过渡到 0.0 和 1.0,以获得淡入淡出效果。如果您选择这种方法,我建议将动画代码放在 -viewWillAppear: 中,例如,如下所示:

[UIView beginAnimations:nil context:NULL]; {
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
        [UIView setAnimationDelegate:self];
        if (toOrientation == UIInterfaceOrientationLandscape) {
                landscapeView.alpha = 1.0;
                portraitView.alpha = 0.0;
        }
        else {
                landscapeView.alpha = 0.0;
                portraitView.alpha = 1.0;
        }
} [UIView commitAnimations];

You can get funky with it and have both background images overlaid, one with alpha = 1.0 and the other with alpha = 0.0. Then, when you rotation, use an animation to transition the alphas to 0.0 and 1.0, respectively to get a fade-in fade-out effect. If you choose this approach, I recommend putting the animation code in -viewWillAppear: For example, something like this:

[UIView beginAnimations:nil context:NULL]; {
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
        [UIView setAnimationDelegate:self];
        if (toOrientation == UIInterfaceOrientationLandscape) {
                landscapeView.alpha = 1.0;
                portraitView.alpha = 0.0;
        }
        else {
                landscapeView.alpha = 0.0;
                portraitView.alpha = 1.0;
        }
} [UIView commitAnimations];
停滞 2024-11-25 00:56:47

您只需将其图像属性设置为不同的图像即可。

someUIImageView.image = [UIImage imageNamed:@"foo.png"];

You can just set its image property to a different image.

someUIImageView.image = [UIImage imageNamed:@"foo.png"];
愿得七秒忆 2024-11-25 00:56:47

现在您实际上可以使用尺寸类别来达到此目的。您需要做的就是将图像设置为任何宽度紧凑高度并执行本文中给出的提示:http://pinkstone.co.uk/how-to-handle-device-rotation-since-ios-8/
这就是背景图像在旋转时发生变化所需的全部内容。

Now you can actually use size classes for this purpose. All you need to do is to set images for Any width compact height and do the hint given in this article: http://pinkstone.co.uk/how-to-handle-device-rotation-since-ios-8/
That's all you need for your background image to change on rotation.

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