问题
Can anyone confirm that [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
will get your app rejected by Apple.
Is there a good replacement available?
回答1:
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientation] is a private API, you can find that is signature is only in read-only (see here).
If you want set the device orientation to Portrait or other mode you should override the shouldAutorotateToInterfaceOrientation:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIDeviceOrientationPortrait);
}
回答2:
Yes you'll get rejected.
You can change the frame and apply a transformation to the key window, and change the status bar orientation (which is public) to simulate changing the orientation.
回答3:
You can add UIInterfaceOrientation in your app plist
回答4:
You can try this code. It works perfectly on my apps
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
AppDelegate* app = [[UIApplication sharedApplication] delegate];
UIViewController *c = [[UIViewController alloc]init];
[app.viewController presentModalViewController:c animated:NO];
[app.viewController dismissModalViewControllerAnimated:NO];
[c release];
}
where app.viewController is the rootViewController of the app
来源:https://stackoverflow.com/questions/2386047/set-interface-orientation-on-iphone-private-api