Enable iPhone Interface Orientation

I am trying to make my application rotate the interface when the device itself rotates, but I cannot figure it out correctly. I added the supported interfaces in the plist info file and returned yes for the shouldRotateToInterfaceOrientation function.

  - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {  
     if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
         return YES;  
     } else {  
         return NO;  
     }  
 } 

Is this how rotation is implemented?
Please help!

+4
source share
4 answers

Perhaps try editing the info.plist file and also add the supported orientations to it?

Choose your project → Choose your goal → Information → Supported interface orientations and click the plus sign 4 times to support these orientations:

Item 0 Landscape (left home button) Item 1 Landscape (right home button) Item 2 Portrait (top home button) Item 3 Portrait (bottom home button) 

Hope this helps!

+1
source

Make sure you add shouldRotateToInterfaceOrientation to the view controllers that you want to support different orientations. He is not a member of the application delegate.

0
source

The supportive orientation is straightforward if you use standard user interface elements, therefore, assuming the case, you are on the right track.

If you use the UITabController, all views must support the same orientations, otherwise it is considered to be minimal by default (for example, Portrait). I suppose.

Also, if you use NIB for your views, make sure you have "Autoresize subviews" when you customize the view in Interface Builder.

0
source

if you are using a UITabBarController then you will need to call its subviews' shouldAutoratateToInterfaceOrientation .

Assuming you have two tabs, try adding the following two lines to the shouldAutorotateToInterfaceOrientation method in a class that uses the UITabViewController .

 [[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation]; [[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 

Of course, the "tabBarController" must be linked to the UITabBarController in your XIB file via IB.

Thanks,

0
source

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