Reputation: 13267
I want the MainView to contain an image so that when I flip a view to another, the user sees the image instead of a blank background. It works fine in portrait mode, but when the user goes into landscape mode, it doesn't work. Here is my code for adding the image in the App Delegate:
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wood.jpg"]];
[self.window addSubview:background];
[self.window sendSubviewToBack:background];
I have also included shouldAutoroate:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
What should I do? Thanks!
Upvotes: 0
Views: 224
Reputation: 4753
The background subview won't rotate because only the first (your main) subview of the window gets rotation events. You can create a view controller for your background view, and in that view controller watch for the rotation events and transform the view accordingly. See Fossili's answer (with flipViewAccordingToStatusBarOrientation) here for an example:
Orientation in a UIView added to a UIWindow
I've tried that on a test app - seems to work nicely.
Upvotes: 1