任何人都可以确认这[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
将使您的应用程序被 Apple 拒绝。
有没有好的替代品?
任何人都可以确认这[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
将使您的应用程序被 Apple 拒绝。
有没有好的替代品?
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientation] 是一个私有API,你可以发现签名是只读的(见这里)。
如果要将设备方向设置为纵向或其他模式,则应覆盖 shouldAutorotateToInterfaceOrientation:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIDeviceOrientationPortrait);
}
您可以更改框架并对关键窗口应用转换,并更改状态栏方向(这是公共的)以模拟更改方向。
你可以试试这段代码。它在我的应用程序上完美运行
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
您可以在应用程序列表中添加 UIInterfaceOrientation