iOS强制splitViewController旋转到横向

iOS强制splitViewController旋转到横向,ios,uiviewcontroller,uisplitviewcontroller,uiinterfaceorientation,autorotate,Ios,Uiviewcontroller,Uisplitviewcontroller,Uiinterfaceorientation,Autorotate,我有一个支持横向和纵向模式的分割视图控制器。当局部视图控制器位于某个视图上时,我禁用纵向,只允许横向。但是,如果用户离开该特定视图,将设备旋转到纵向,然后返回到该特定视图,则设备仍处于纵向。我需要它自动旋转回风景区。下面是我正在使用的。这些方法都是从我的子类UISplitViewController调用的,因此方向可以依赖于视图控制器 #pragma mark - Orientation - (BOOL)shouldAutorotate { // Allow view controll

我有一个支持横向和纵向模式的分割视图控制器。当局部视图控制器位于某个视图上时,我禁用纵向,只允许横向。但是,如果用户离开该特定视图,将设备旋转到纵向,然后返回到该特定视图,则设备仍处于纵向。我需要它自动旋转回风景区。下面是我正在使用的。这些方法都是从我的子类UISplitViewController调用的,因此方向可以依赖于视图控制器

#pragma mark - Orientation

- (BOOL)shouldAutorotate
{
    // Allow view controller to rotate between landscapes
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    // Return supported interface orientation
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    // Return preferred orientation
    return UIInterfaceOrientationLandscapeLeft;
}
// This has worked for me - assumes ARC is enabled

- (void)forceLandscape
{
    UIDevice  *myDevice = [UIDevice currentDevice];
    if([myDevice respondsToSelector:@selector(setOrientation:)])
    {
        NSInteger param     = UIInterfaceOrientationLandscapeRight;
        NSMethodSignature *signature  = [[myDevice class] instanceMethodSignatureForSelector:@selector(setOrientation:)];
        NSInvocation      *invocation = [NSInvocation invocationWithMethodSignature:signature];
        [invocation setTarget:myDevice];
        [invocation setSelector:@selector(setOrientation:)];
        [invocation setArgument:&param
                        atIndex:2];
        [invocation invoke];
    }
}