self.window.rootViewController.presentedViewController
尽管有 viewController 可用,但总是返回nil 。不知道我做错了什么。
以下是完整代码-
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSLog(@"this is loaded");
if ([self.window.rootViewController.presentedViewController isKindOfClass:[SecondViewController class]])
{
SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController;
if (secondController.isPresented)
{
return UIInterfaceOrientationMaskLandscape;
}
else return UIInterfaceOrientationMaskPortrait;
}
else return UIInterfaceOrientationMaskPortrait;
}