我创建了一个我希望能够旋转的视图。这两个意见是: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和只是用于演示。