【发布时间】:2010-06-16 14:46:38
【问题描述】:
我创建了一个我希望能够旋转的视图。这两个视图是: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,仅用于演示。
【问题讨论】: