UISplitViewController and orientation - iOS < 5.0

a 夏天 提交于 2019-12-04 03:18:05

问题


I am using a splitviewcontroller as the rootview of my application. I need to show the login and registration views as a modal view on top of the splitviewcontroller. When i try presenting login/reg view from the viewdidAppear method of splitViewController's rootview, it is not showing up. I tried presenting the login/reg view from the Appdelegate's didFinishLaunching method using the following code

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

and it works.

My problem is, the application supports both the landscape orientations, but when i run it in the device, no matter in which orientation i hold the device, I get only LandscapeRight as orientation. So if i hold the device in LandscapeLeft orientation, app lauches with login screen upside down. I am using LandscapeLeft & Right in supported orientations on the info.plist.

Please help me resolve the issue. Also how will we present a view when we have splitViewcontroller as the rootview of the app?

In iOS 5.0 (only) I am able to present the login view from the splitviewcontroller's rootview controller - viewdidAppear method. In all other OS versions, this case is not working and i need to present it from the Appdelegate's didFinishLaunching method.


回答1:


If I remember correctly, iOS misreports the actual orientation until the first rotation.

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




回答2:


After removing the login view from the window set the rootviewcontroller direction according to the orientation of device using 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 Rootviewcontroller according to the device orientation.



来源:https://stackoverflow.com/questions/8738462/uisplitviewcontroller-and-orientation-ios-5-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!