Hi,
I have created a view that I want to be able to rotate. The two views are: containerView
and this has a .backgroundColor
of red and BackgroundImage
as a subview. Here is my code for rotating:
- (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";
}
}
The problem is that the image rotates, but the background color is shown whilst the view rotates. Is there a nice solution to this problem (I know that I could create the images to blend into a color and set the background to the same color, but this is not what I would like).
A Video of the problem can be seen here:http://tinypic.com/r/2quj24g/6
PS the images are from the OmniGroup GitHub repo and are just used for the demo.