如何使用UISplitViewController iOS强制在iPad上以纵向模式显示MasterViewController

时间:2016-07-02 06:34:21

标签: ios objective-c swift uisplitviewcontroller

我正在使用UISplitViewController创建应用,但它需要在Ipad中仅显示纵向模式下的MasterViewController(与iPhone上的纵向模式相同)。在横向模式下,它可以正常工作。

请给我一些想法。提前谢谢。

3 个答案:

答案 0 :(得分:0)

plz在app delegate class

中使用此代码
 -(id)getTopViewController{


           UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;

            while (topController.presentedViewController) {
                topController = topController.presentedViewController;
            }
            if (![topController isKindOfClass:[NSNull class]]) {

                return topController;
            }



    }


- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{



      UIViewController *viewOb = [self getTopViewController];


    if ([viewOb isKindOfClass:[MasterViewController class]]) {
        return UIInterfaceOrientationMaskPortrait;


    }



    return UIInterfaceOrientationMaskAll;
}

答案 1 :(得分:0)

将其放入viewWillAppear

NSNumber *value = [NSNumber numberWithInt: UIInterfaceOrientationMaskPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

答案 2 :(得分:0)

请使用此代码,它将帮助您

- (BOOL)shouldAutorotate{
    //disable rotation
    return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    //allow only portrait interface orientation
    return UIInterfaceOrientationMaskPortrait;
}