IOS7 / IOS8 Allow portrait controller only

I am creating an application for the iPhone that will have only one landscape view, so I want to block the landscape for everyone else, I tried this:

-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 

But he is still spinning

+2
source share
2 answers

I suggest just making your application for portrait mode, and then whenever you need landscape mode, then enable landscape.

First, as previously suggested, click on → Project Name → General → Deployment Information → Select only a portrait for device orientation.

Secondly, in 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 that, in the view controller that you need the landscape, create a function or just add this code to your viewWillAppear method, depending on how you want to accomplish this.

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

Then, to return 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 may need these features 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; } 

Hope this helps .. :)

+9
source

Select a project and select Orientation Settings.

-3
source

Source: https://habr.com/ru/post/1202316/


All Articles