开发者

iPad Initial Orientation

开发者 https://www.devze.com 2023-03-03 12:00 出处:网络
I\'m having a really hard time making my app to support all orientations correctly. The issue is with start up. I\'ve done the following steps:

I'm having a really hard time making my app to support all orientations correctly. The issue is with start up. I've done the following steps:

  1. Added :

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    
  2. Made sure that all my view controllers always return YES in shouldAutorotateToInterfaceOrientation
  3. Added all the Default* images

When in landscape - the application starts showing the correct Default image, but then the actual app starts in portrait. The willRotate... and shouldAutorotate.. methods are not called.

I've ev开发者_开发知识库en tried the swizzling method (from Wordpress):

+ (void)youWillAutorotateOrYouWillDieMrBond {
    NSLog(@"youWillAutorotateOrYouWillDieMrBond");
    Swizzle([NSClassFromString(@"UISplitViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
    Swizzle([NSClassFromString(@"UIViewController") class], @selector(shouldAutorotateToInterfaceOrientation:), @selector(MyShouldAutorotateToInterfaceOrientation:), NULL);
}

- (BOOL)MyShouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    NSLog(@"MyShouldAutorotateToInterfaceOrientation (%@)", self);
    return(YES);
}

Also with no luck. No matter what I do - if the device is in landscape, the app starts as portrait.

I've read the corresponding Apple docs - and they state that the applications always start in portrait but then rotate themselves if the VCs support the orientation. So seems I am doing everything as I should...

Really out of ideas here, would appreciate any insight.


Ok, thanks to everyone who helped, but it wasn't one of the proposed solutions: Seems I've stumbled on some iPAD bug.

The solution was simple:

The Master view didn't receive any events for some reason, and that was the problem. What I did was wrap that UIViewController inside a UINavigationController and set it as Master. Then the navigation controller DID receive the events and passed them on. Problem solved!


It could be the problem that your nib is setup in the wrong mode. You can change the nibs starting position to be either landscape or portait. I have found that is easier than working with the view controller.

To do this go to Interface builder, select the view. Select the left-most tab in the 'View Attributes' window and change Orientation to landscape.


First, check you have all four UISupportedInterfaceOrientations into your info.plist

Next, check you're adding your split view to the app window (eg. [self.window addSubview:splitViewController.view];) in the app delegate's applicationDidFinishLaunchingWithOptions, and not later, which can cause this problem.

Alternatively, UIWindow only reliably passes the rotation to the view controller of the first view that is added to the window. Depending on how you did your split view controller, this might be the issue. Make sure that any views you need rotated correctly are in the subview hierarchy of whatever is the first of the view added to the window so that it's view controller can properly pass the rotation events down.

Hope that helps!


If you cannot solve the problem, try addind this to your Info.plist file. It works for me in my universal application:

<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

The difference here is that you force these properties to be iPad-specific through the ~ipad snippet.

If you want to force the orientation upon the launch of the app, you should try updating the applicationDidFinishLaunching: method adding this, to force notifications of change of orientation:

UIDevice *device = [UIDevice currentDevice];
[device beginGeneratingDeviceOrientationNotifications];

Hope this helps.

If this does not work, it could be a problem related to the initialization of your app, i.e. the way you create the UISplitViewController and add the side and detail controllers to it. In such a case, please, past that piece of code.

0

精彩评论

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

关注公众号