我是 iOS 开发的新手,刚刚继承了一堆 iOS 代码。
我正在尝试开始使用自动布局和约束,以便更轻松地支持不同的屏幕尺寸和 iOS 版本。我发现一旦我将 Storyboard更改为使用自动布局,当我将 iPad 旋转到横向 View 时背景图像不再改变。我不确定这是否是阻止此更改的自动布局,或者是否有其他方法可以切换背景图像。我很感激你的帮助。
这是我的旋转方法。
- (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];
}
}
最佳答案
向基础 View (这是一个按钮)添加新的值为零的左、右和上约束解决了这个问题。
关于iOS - 使用自动布局在旋转时更改背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23568862/