我创建了一个我希望能够旋转的视图。这两个观点为:containerView
,其中.backgroundColor
为红色,BackgroundImage
为子视图。这是我的旋转代码:
- (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,仅用于演示。
答案 0 :(得分:2)
此问题的解决方案是将UIView或UIWindow的backgroundColor
设置为[UIColor blackColor]
。当您旋转Safari时,会发生同样的事情,只是背景颜色是黑色的,就像通常应该的那样。 iPad上的所有应用都以这种方式旋转,用户不会发现任何差异。
PS-使用willRotateToInterfaceOrientation:duration:
willAnimateRotationToInterfaceOrientation:duration:
方法
答案 1 :(得分:0)
您可以使图像大于屏幕尺寸。因此,在iPhone上,将图像设置为480 x 480.或者在您的情况下,1024 x 1024。