IOS7/IOS8 Allow only portrait in view controller

后端 未结 2 1995
长情又很酷
长情又很酷 2021-01-14 23:51

I am building an app for iPhone that will have only 1 landscape view, and so i want to block landscape for all other, i have tried this:

-(NSUInteger)suppor         


        
相关标签:
2条回答
  • 2021-01-15 00:08

    Click project and select Orientation settings from there.

    0 讨论(0)
  • 2021-01-15 00:17

    I will suggest to just make your app for portrait mode and then whenever you need the landscape mode then allow landscape mode.

    First, as previously suggested click on -> Project name -> General -> Deployment Info -> Only select Portrait for Device Orientation.

    Second, in your AppDelegate.h add this property..

    @property (nonatomic) BOOL fullScreenVideoIsPlaying;
    

    Then, on your AppDelegate.m I will add this function..

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
        if (self.fullScreenVideoIsPlaying == YES) {
            return UIInterfaceOrientationMaskAllButUpsideDown;
        }
        else {
            return UIInterfaceOrientationMaskPortrait;
        }
    }
    

    After doing this, in the view controller that you need landscape create a function or just add this code to your viewWillAppear method is depending how you want to accomplish this..

    ((AppDelegate *)[[UIApplication sharedApplication] delegate]).fullScreenVideoIsPlaying = YES;
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    

    Then for setting back to portrait mode you do this..

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        appDelegate.fullScreenVideoIsPlaying = NO;
    
    [self supportedInterfaceOrientations];
    
    [self shouldAutorotate:UIInterfaceOrientationPortrait];
    
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
    

    You might need these functions for iOS 8..

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    - (BOOL)shouldAutorotate:(UIInterfaceOrientation)interfaceOrientation{
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    -(NSUInteger)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskPortrait;
    }
    

    I hope it helps.. :)

    0 讨论(0)
提交回复
热议问题