iOS9支持的InterfaceDirectionsforWindow停止调用
我想在横向模式下显示1或2个UIViewController,而在纵向模式下显示其他UIViewController。 为此,我在AppDelegate中实现了这个函数iOS9支持的InterfaceDirectionsforWindow停止调用,ios,objective-c,orientation,uiinterfaceorientation,Ios,Objective C,Orientation,Uiinterfaceorientation,我想在横向模式下显示1或2个UIViewController,而在纵向模式下显示其他UIViewController。 为此,我在AppDelegate中实现了这个函数 -(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return self.orientation; } 其中
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return self.orientation;
}
其中,在AppDelegate.h中,方向为:
@property (nonatomic, assign) UIInterfaceOrientationMask orientation;
在UIViewcontroller中,我需要横向定位。我把这个密码
-(void)viewWillAppear:(BOOL)animated
{
self.appDelegate.orientation = UIInterfaceOrientationMaskLandscape;
}
及
但是,当我转到“LandscapeViewController”时,它工作正常,我返回,它工作正常,我再次转到“LandscapeViewController”它工作正常,然后当我返回时,SupportedInterfaceDirectionsforWindow方法停止调用。有什么原因吗?或者我正在做一些奇怪的事情?如果您正在使用UITabBarController,请为UITabBarController创建一个自定义类,并将此代码放在那里
-(UIInterfaceOrientationMask) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
并根据需要将其放置在视图控制器中
将此代码放在appDelegate中
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
id rootViewController = [self topViewControllerWithRootViewController:window.rootViewController];
if (rootViewController != nil)
{
if ([rootViewController respondsToSelector:@selector(canRotate)])
{
return UIInterfaceOrientationMaskLandscape;
}
}
return UIInterfaceOrientationMaskPortrait;
}
-(UIViewController*) topViewControllerWithRootViewController:(id)rootViewController
{
if (rootViewController == nil)
{
return nil;
}
if ([rootViewController isKindOfClass:[UITabBarController class]])
{
UITabBarController *selectedTabBarController = rootViewController;
return [self topViewControllerWithRootViewController:selectedTabBarController.selectedViewController];
}
else if ([rootViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *selectedNavController = rootViewController;
return [self topViewControllerWithRootViewController:selectedNavController.visibleViewController];
}
else
{
UIViewController *selectedViewController = rootViewController;
if (selectedViewController.presentedViewController != nil)
{
return [self topViewControllerWithRootViewController:selectedViewController.presentedViewController];
}
}
return rootViewController;
}
并将其放置在视图控制器中
-(void)canRotate
{
}
-(void)canRotate
{
}