I am having trouble starting the app in landscape mode. The view is always shown in portrait mode.
I have the following configured in the plist:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
The UIViewController is created in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.myViewController = [MyViewController alloc];
UIView *myView = [[UIView alloc] init];
myView = [UIColor whiteColor];
self.myViewController.view = myView;
self.window.rootViewController = self.myViewController;
self.window makeKeyAndVisible];
return YES;
}
Added shouldAutorotateToInterfaceOrientation to MyViewController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
When the device is in portrait mode and the app starts, the status bar is in landscape mode. However when the UIView gets shown, it will end up in portrait mode. The same thing happens when the device is in landscape mode.
However, when I create the UIViewController in Interface Builder, it works.
Is this related to autoresizemasking because it didn't work when I add this in AppDelegate.m:
myView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ;