Xcode - How to keep viewing locked in portrait mode, but still allow rotation of one view?

I had a problem with the rotation of the device. With the exception of ONE view, where I show the company screensaver, I want to block all other types of applications on the portrait display. In the project settings, the supported orientations are Portrait and LandscapeLeft. At Splash Company, it works great, and the rotation of my vision is blocked in LandscapeLeft no matter how I rotate the device. In all other views, when I turn the device to the left, the view changes instead of remaining on the portrait display. Do the methods not even shoot? If I delete an album remaining from the supported Orientations in the project, it overshadows the look of the "Splash" company. I tried changing shouldAutorotate to NO , but that didn't help. I tried to make my way through the proposed proposals here , but it did not help. If I add the following code to my AppDelegate.m, everything will be blocked in portrait mode, and upon access, the "Company Splash" crashes.

 -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; } 

How to block viewing in portrait mode no matter how the device is turned, except for one screen?

** from the presentation "Company Splash". Again, it works as intended.

 -(NSInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeLeft; } 

** from all other species that rotate from a portrait when I do not want them

 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // IOS5 Only returning that it should rotate to potrait return (interfaceOrientation == UIDeviceOrientationPortrait); } -(BOOL)shouldAutorotate { // forcing the rotate IOS6 Only return YES; } -(NSInteger)supportedInterfaceOrientations { // return number or enum IOS6 Only return UIInterfaceOrientationMaskPortrait; } 

I thought maybe this could be because the UITabBarController is the root controller and am I in the ViewController? Do the methods not even shoot?

+3
source share
3 answers

Add an observer to the viewDidLoad method of the view you want to rotate as follows:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]]; 

and then set the views according to the landscape view inside the orientationChanged method as follows:

 - (void) orientationChanged:(NSNotification *)note{ UIDevice * device = [UIDevice currentDevice]; switch(device.orientation) { case UIDeviceOrientationPortrait: break; case UIDeviceOrientationPortraitUpsideDown: break; case UIDeviceOrientationLandscapeLeft: break; case UIDeviceOrientationLandscapeRight: break; default: break; }; } 
+6
source

Place this method in the view controller that you want to lock in a specific orientation.

 -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 

just change the orientation you want (the above blocks it in the landscape)

+2
source

perhaps you should allow all orientations and block portrait orientation in each class except the surge of the company with

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation == UIInterfaceOrientationPortrait) { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } else { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); } } 
0
source

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


All Articles