Я создал представление, что я хочу смочь вращаться. Два представления: containerView
и это имеет a .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";
}
}
Проблема состоит в том, что изображение вращается, но цвет фона показывают, пока представление вращается. Есть ли хорошее решение этой проблемы (я знаю, что мог создать изображения, чтобы смешаться с цветом и установить предпосылки к тому же цвету, но это не то, что я хотел бы).
Видео проблемы видно here:http://tinypic.com/r/2quj24g/6
PS изображения от OmniGroup GitHub repo и просто используются для демонстрации.
Решением этой проблемы является установка backgroundColor
UIView или UIWindow в [UIColor blackColor]
. Когда вы поворачиваете Safari, происходит то же самое, только цвет фона становится черным, как и должно быть. Все приложения на iPad вращаются таким образом, и пользователь не заметит никакой разницы.
PS- Вместо использования метода willRotateToInterfaceOrientation:duration:
используйте willAnimateRotationToInterfaceOrientation:duration: