2010-06-16 116 views
1

我创建了一个我希望能够旋转的视图。这两个意见是:containerView,这有一个.backgroundColor红色和BackgroundImage作为子视图。这里是我的旋转代码:iOS - 旋转视图显示背景

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [self adjustViewsForOrientation:toInterfaceOrientation]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { 
    backgroundImage.image = [UIImage imageNamed:@"landscape.jpg"]; 
    backgroundImage.frame = CGRectMake(0, 0, 1024, 704); 
    containerView.frame = CGRectMake(0, 0, 1024, 704); 
    self.title = @"landscape"; 
    } else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
    backgroundImage.image = [UIImage imageNamed:@"portrait.jpg"]; 
    backgroundImage.frame = CGRectMake(0, 0, 768, 960); 
    containerView.frame = CGRectMake(0, 0, 768, 960); 
    self.title = @"portrait"; 
    } 
} 

问题是图像旋转,但背景颜色显示,而视图旋转。有没有一个很好的解决这个问题(我知道我可以创建图像混合成一种颜色,并将背景设置为相同的颜色,但这不是我想要的)。

问题的视频可以在这里看到:http://tinypic.com/r/2quj24g/6

PS的图片均来自OmniGroup GitHub repo和只是用于演示。

回答

2

解决此问题的方法是将UIView或UIWindow的backgroundColor设置为[UIColor blackColor]。当你旋转Safari时,会发生同样的事情,只是背景颜色是黑色的,就像它通常应该那样。 iPad上的所有应用程序都以这种方式旋转,用户不会注意到任何差异。

而不是使用willRotateToInterfaceOrientation:duration:方法的PS-,使用willAnimateRotationToInterfaceOrientation:duration:

0

你可以让你的图像比屏幕尺寸更大。因此,在iphone上,使图像为480 x 480。或在您的情况下,1024 x 1024.