views:

246

answers:

1

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.

+1  A: 

The solution to this problem is to set the UIView's or UIWindow's backgroundColor to [UIColor blackColor]. When you rotate Safari, the same exact thing happens, just the background color is black, like it normally should be. All the apps on the iPad rotate this way, and the user will not notice any difference.

PS- Instead of using the willRotateToInterfaceOrientation:duration: method, use willAnimateRotationToInterfaceOrientation:duration:

ckrames1234