自动旋转/背景图像:如何摆脱平铺效果?最佳实践?

时间:2012-08-18 23:18:34

标签: ios autorotate

我有这段代码在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等的方法。

两个问题:

  1. 我可以通过简单地将此代码(可能稍加修改)移动到另一种方法(可能会影响效果的时间)来避免这种平铺效果吗?
  2. 如果我需要更详细的动画,我应该使用哪种方法?指向示例的任何指针?
  3. 感谢。我已经做了很多阅读,但似乎有很多方法可以让它几乎正确,如果有人对最佳实践发表评论,我会很感激。

1 个答案:

答案 0 :(得分:2)

解决方案:除了将肖像和横向的实例交换到willAnimateRotationToInterfaceOrientation之外,我将相同的代码添加到{{1}}并修复了平铺问题。