手动设置界面方向
答
一种方法,我知道这对我的作品(并且是一个黑客位,并可以改变到你想要的方向之前显示一个方向)是:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}
}
答
覆盖它来控制方向,直到装...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
+0
方向属性为只读 –
+0
是的,您是对的。我的错。我更新了我的答案。您可以考虑重写shouldAutorotateToInterfaceOrientation并根据需要维护方向。 – Saran
答
首先,设置你的应用程序和观点,只支持人像,然后使用从我的重构库中提取的这一类方法,es_ios_utils:
@interface UIViewController(ESUtils)
// Forces without using a private api.
-(void)forcePortrait;
@end
@implementation UIViewController(ESUtils)
-(void)forcePortrait
{
//force portrait orientation without private methods.
UIViewController *c = [[UIViewController alloc] init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}
@end
该视图在帧完成前关闭,将不会显示。
这实际上对我描述的情况非常有效。但由于某些原因,不适合尝试从纵向模式强制横向(将UIInterfaceOrientationPortrait更改为UIInterfaceOrientationLandscapeLeft)。想法? –
实际工作的肮脏的黑客。 – beefon
谢谢!伟大的代码行=) – CReaTuS