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