set interface orientation on iPhone private API

南楼画角 提交于 2019-12-11 12:51:35

问题


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

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