在iPhone专用API上设置界面方向
问题描述:
任何人都可以确认[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
会让您的应用被Apple拒绝。在iPhone专用API上设置界面方向
有没有好的替代品可用?
答
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientation]是一个私有API,你可以发现签名是只读的(见here)。
如果你想设置的设备方向为纵向或其他方式,你应该覆盖shouldAutorotateToInterfaceOrientation:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIDeviceOrientationPortrait);
}
答
您可以在您的应用程序的plist
答
你可以试试这段代码。它完美对我的应用程序
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];
}
其中app.viewController是应用程序的RootViewController的
的UIDevice是不是私人的API。 – thierryb 2010-03-05 13:23:22
对不起,这是一个错误,我只是告诉setOrientation是私人的。 – 2010-03-05 13:36:04