【问题标题】:iOS - Change background image on rotate using auto layoutiOS - 使用自动布局在旋转时更改背景图像
【发布时间】:2014-05-09 15:47:47
【问题描述】:

我对 iOS 开发还很陌生,只是继承了一堆 iOS 代码。

我正在尝试开始使用自动布局和约束,以便更轻松地支持不同的屏幕尺寸和 iOS 版本。我发现一旦我将故事板更改为使用自动布局,当我将 iPad 旋转到横向视图时,背景图像就不再改变。我不确定这是否是阻止此更改的自动布局,或者是否有其他方法可以切换背景图像。我会很感激你的帮助。

这是我的旋转方法。

- (void)didRotate
{
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;

    if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone)
    {
        if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
        {
            [backgrndView setBackgroundImage:[UIImage imageNamed:@"menu_ipad2.png"] forState:UIControlStateNormal] ;
        }
        else if (orientation == UIDeviceOrientationPortraitUpsideDown|| orientation == UIDeviceOrientationPortrait)
        {
            [backgrndView setBackgroundImage:[UIImage imageNamed:@"menu_ipad.png"] forState:UIControlStateNormal] ;
        }

        [backgrndView sizeToFit];
    }
}

【问题讨论】:

    标签: ios ipad autolayout


    【解决方案1】:

    将值为零的新左、右和上约束添加到底层视图(这是一个按钮)解决了这个问题。

    【讨论】:

      【解决方案2】:

      我相信您要覆盖的方法是 didRotateFromInterfaceOrientation: 而不是 didRotate

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-24
        • 2013-07-05
        • 1970-01-01
        • 1970-01-01
        • 2012-04-18
        • 2017-07-01
        相关资源
        最近更新 更多