UISplitViewController and Orientation - iOS <5.0

I am using splitviewcontroller as the rootview of my application. I need to show the login and registration view as a modal view on top of the splitview controller. When I try to present the login / reg view from the viewdidAppear method in the splitViewController root directory, it does not appear. I tried to present the login / reg view from the appdelegate didFinishLaunching method using the following code

 [self.window.rootViewController presentModalViewController:self.navController animated:NO]; 

and it works.

My problem is that the application supports both landscape orientation, but when I run it on the device, no matter what orientation I hold the device in, I only get LandscapeRight as orientation. Therefore, if I hold the device in the LandscapeLeft orientation, the lauches application with the login screen upside down. I use LandscapeLeft and Right in the supported orientations on info.plist.

Please help me solve the problem. Also, how do we present the view when we have splitViewcontroller as the root directory of the application?

In iOS 5.0 (only) I can imagine the login view from the rootviewcontroller rootview controller - viewdidAppear. In all other OS versions, this case does not work, and I have to present it from the appdelegate didFinishLaunching method.

+6
source share
2 answers

If I remember correctly, iOS incorrectly captures the actual orientation until the first turn.

Also, IIRC, using [[UIApplication sharedApplication] statusBarOrientation] , circumvents this problem.

0
source

After removing the login window from the window, set the direction of the rootviewcontroller according to the orientation of the device using the following code.

 #define DegreesToRadians(x) ((x) * M_PI / 180.0) [LoginviewContoller.view removeFromSuperview] self.viewController = [[[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil] autorelease]; switch(self.viewController.interfaceOrientation) { case UIInterfaceOrientationPortrait: NSLog(@"potrait"); break; case UIInterfaceOrientationPortraitUpsideDown: NSLog(@"prtraitdown"); break; case UIInterfaceOrientationLandscapeLeft: self.viewController.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(270)); NSLog(@"lanscapelef"); break; case UIInterfaceOrientationLandscapeRight: self.viewController.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(90)); NSLog(@"landcsape righ"); break; } [self.window addSubview:self.viewController.view]; 

It will load the Rootview controller according to the orientation of the device.

-1
source

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


All Articles