Presenting Navigation Controller in Landscape mode is not working ios 6.0

前端 未结 2 1176
梦毁少年i
梦毁少年i 2021-01-23 16:16

This is my code.

 SomeController *analyticsViewController = [[SomeController alloc] init];

 MTNavigaionLandscapeViewController *analyticsNavigaionObject =  [[MT         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 16:29

    Write these methods in your ViewController which you are going to present:

    - (BOOL)shouldAutorotate
    {
        AppDelegate *mainDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
        mainDelegate.shouldRotate = YES;
        return YES;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeRight;
    }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return YES;
    }
    

    In your AppDelegate.m paste this

    - (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        if(self.shouldRotate)
        {
            self.shouldRotate = NO;
            return UIInterfaceOrientationMaskLandscapeRight;
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    

    In your AppDelegate.h paste this

    @property (assign, nonatomic) BOOL shouldRotate;
    

    In your presentingViewController in ViewWillAppear paste this:

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
    

提交回复
热议问题