Force orientation to Portrait Mode

后端 未结 1 1892
野趣味
野趣味 2021-01-23 20:07

I have all the app in portrait mode, but I have one of the viewcontroller in landscape mode to be a gallery of images.

On the tab Project Summary enable LandscapeLeft mo

相关标签:
1条回答
  • 2021-01-23 20:36

    For Portrait Mode VC,

    #pragma mark iOS 5 Orientation Support
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
         return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    
    #pragma mark iOS 6 Orientation Support
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    For Landscape mode VC,

    #pragma mark - iOS 5.0 and up Rotation Methods
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
        return UIInterfaceOrientationMaskLandscape;
    
    }
    
    #pragma mark - iOS 6.0 and up Rotation Methods
    
    - (NSUInteger)supportedInterfaceOrientations;
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    

    If you are using navigationController,

    Create a category like this,

        @interface UINavigationController (Rotation_IOS6)
    
        @end
    
        @implementation UINavigationController (Rotation_IOS6)
    
        -(BOOL)shouldAutorotate
        {
            if([self.visibleViewController isMemberOfClass:NSClassFromString(@"YourLandscapeViewController")])
            {
                return UIInterfaceOrientationMaskLandscape
            }
            return NO;
        }
    
        - (NSUInteger)supportedInterfaceOrientations
        {
            return [[self topViewController] supportedInterfaceOrientations];
        }
    
        - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
        {
            if([self.visibleViewController isMemberOfClass:NSClassFromString(@"YourLandscapeViewController")])
            {
                return UIInterfaceOrientationMaskLandscape
            }
            return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
        }
    
    @end
    
    0 讨论(0)
提交回复
热议问题