我有2个视图控制器.我希望第一个viewcontroller只是Portrait模式,而第二个viewController应该支持所有方向.请帮我.
在AppDelegate类中,我的代码是:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.viewController;
// [self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSLog(@"supportedInterfaceOrientationsForWindow");
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
第一个ViewController代码是:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
第二个ViewController代码是:
-(NSUInteger)supportedInterfaceOrientations …Run Code Online (Sandbox Code Playgroud)