开发者

iPad UISplitViewController Launch Orientation - Root View Displayed In Portrait

So I have a UISplitViewController that is the root view of my program. I have set the initial orientation to be LandscapeLeft and have all 4 orientations supported in my plist.

If I launch the app in portrait - the view that is shown is my root view not the detail view which obviously is not what I want. As soons as I rotate the device, everything works from there.

I have scoured this site a开发者_StackOverflownd others but have found no fixes. The closest I have come is the adding the following to my app delegate:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

if (UIDeviceOrientationIsValidInterfaceOrientation([UIDevice currentDevice].orientation)) {
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
    else
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
}

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

So this essentially forces it to draw correctly, which works great except for when the app launches with the device laying flat. Then I dont know the portrait vs landscape (and I know of no way to find it). So I basically then cant accurately say what to do.

The larger thing is this above code is a HACK, and there should be a better way, but for the life of me I cant find it.

Any ideas?


Thanks for your code on fixing this for portrait and landscape. I found a quick fix for the issue when its flat on the desk or upside down(not sure who would start the app upside down, but the same issue happens in this case):

if (UIDeviceOrientationIsValidInterfaceOrientation([UIDevice currentDevice].orientation)) {
    if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
    else if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;


}
else {

    if (([UIApplication sharedApplication].statusBarOrientation == 1) || ([UIApplication sharedApplication].statusBarOrientation == 0))
    {
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
    }
    else {
        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
    }

    NSLog(@"orientation: %d", [UIApplication sharedApplication].statusBarOrientation);

}

In my App, this works because I just wanted to force them into portrait to start and if they move to landscape after that, it rotates and works fine because I support all orientations.

I don't think this will work in all cases, but this might help you get on the right track. You just need to play with the statusBarOrientation value and manually set it based on what you find works if the InterfaceOrientation is not valid(which it isn't if the device is flat on a table or upside down).

Hope that helps...

Edit: Also, I have a need in my App for knowing orientation while they are picking new items in the SplitViewController, so it was being wonky when the device was flat or upside down. And the way I detected if it was flat or upside down was to first see if the orientation was valid like you did:

if (UIDeviceOrientationIsValidInterfaceOrientation([UIDevice currentDevice].orientation))

But then if its not, I check to see if self.popoverController is nil. If its not, then its in portrait and if it is, then its landscape (based on how the splitViewController works by setting that to nil or not):

if (self.popoverController)
        {
            NSLog(@"in portrait");

        }
        else {
            NSLog(@"in landscape");

        }

This wouldn't work in the App Delegate while the App is launching though because this detailViewController isn't being used at that point. Just thought I'd let you know if it helps out any.


Your RootViewController is showing in place of your detailViewCOntroller? it seems you're doing something bad... (maybe inverted viewControllers order in SplitViewController.viewControllers ?)


You need to make sure to add your UISplitViewController's view to the UIWindow INSIDE the application:application didFinishLaunchingWithOptions: method of your app delegate (not later), or the split view won't rotate correctly initially.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜