我有这段代码在iPad上旋转时更改背景图片:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (![SysConfig isPhone]) { // Only need to worry about this for the iPad
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
if ([SysConfig isRetina]) {
if (UIInterfaceOrientationIsLandscape(fromInterfaceOrientation)) {
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Default-Portrait@2x~ipad.png"]]];
} else {
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Default-Landscape@2x~ipad.png"]]];
}
// retina display above, regular below
} else {
\\ Same thing but for low res display
}
}
}
}
它工作正常,只是短暂地看到原始背景图像平铺在新旋转的设备上,然后它旋转并转移到适合新方向的新图像就好了,所以它不会平铺。我想摆脱平铺的视觉效果。
我从阅读中收集起来,我可能会通过某种动画隐藏平铺(交叉淡化两个图像,或收缩旧图像并在旋转发生时将其平滑展开为新图像)。但我也不确定我是否在正确的地方这样做,因为我看到涉及viewDidAppear
viewWillAppear
willAnimateRotationToInterfaceOrientation
等的方法。
两个问题:
感谢。我已经做了很多阅读,但似乎有很多方法可以让它几乎正确,如果有人对最佳实践发表评论,我会很感激。
答案 0 :(得分:2)
解决方案:除了将肖像和横向的实例交换到willAnimateRotationToInterfaceOrientation
之外,我将相同的代码添加到{{1}}并修复了平铺问题。