简体   繁体   English

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

[英]iphone background images when changing device rotation

I have an UIImageView as a background behind my controls, the problem comes when rotating the device.我的控件后面有一个UIImageView作为背景,旋转设备时出现问题。 I'd like to use a different image depending on the orientation .我想根据orientation使用不同的image

So what would be the best way to handle that?那么处理这个问题的最佳方法是什么? Adding and removing each UIImageView for landscape and portrait?为横向和纵向添加和删除每个UIImageView Having both on the view and hide/show the appropriate one?既有视图又有隐藏/显示合适的视图? Or maybe there is some class or UIObject for handling that?或者也许有一些 class 或UIObject来处理?

TIA TIA

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.您需要做的就是为 Any width compact height 设置图像并执行本文中给出的提示: http://pinkstone.co.uk/how-to-handle-device-rotation-since-ios-8/那就是旋转时更改背景图像所需的一切。

You can just set its image property to a different image.您可以将其图像属性设置为不同的图像。

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

You can get funky with it and have both background images overlaid, one with alpha = 1.0 and the other with alpha = 0.0.您可以使用它变得时髦,并叠加两个背景图像,一个具有 alpha = 1.0,另一个具有 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.然后,当您旋转时,使用 animation 将 alpha 分别转换为 0.0 和 1.0,以获得淡入淡出效果。 If you choose this approach, I recommend putting the animation code in -viewWillAppear: For example, something like this:如果选择这种方式,我建议将 animation 代码放在-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];

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

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