2012-07-23 37 views
2

我有一个splitcontroller和有模式地显示来自detailcontroller的viewDidLoad中(它的登录屏幕)一个模式的普遍应用检测上的应用程序启动正确的方向

当打开iPad版,我想能够在纵向或横向上启动它取决于设备的初始方向。问题在于它始终以纵向形式启动(预计按照documentation)。

如果我有设备作为肖像,然后转动景观,它的作品。但是如果我直接打开应用程序,它不会。

BTW:我已经设置return true在那个登录的viewController的(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

更新: 如果我从viewDidAppear而不是viewDidLoad中进行SEGUE,模态的方向正常工作,但SplitController被视作一个而在模态之前,我该如何避免这种情况?

- (void)viewDidAppear:(BOOL)animated 
{ 
    [self.splitViewController performSegueWithIdentifier:@"toModal" sender:self.splitViewController]; 
} 

回答

1

您可以有条件地设置(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation的方向。这样的事情是不漂亮,但它的工作原理:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

if(orientation == 0) //Default orientation 
    //UI is in Default (Portrait) -- this is really a just a failsafe. 
else if(orientation == UIInterfaceOrientationPortrait) 
    //Do something if the orientation is in Portrait 
else if(orientation == UIInterfaceOrientationLandscapeLeft) 
    // Do something if Left 
else if(orientation == UIInterfaceOrientationLandscapeRight) 
    //Do something if right 

否则这个职位看起来很相对于你想做什么:

Launching application in landscape orientation for IPad


提案2


您可以创建一个具有方法的类来查找dev的方向冰(即使用 'deviceInfo'):

UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation]) 

UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]statusBarOrientation]) 

您还可以存储任何拉伸因素/尺寸/测量你在乎曾经拥有。然后在view-(id)initWithFrame:(CGRect)frame中,您可以调用您的方法来检查方向(即deviceInfo.isLandscape?)。然后设定你viewautoresizingMask等于UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth。然后,在-(void)layoutSubviews设置view.frame等于你想要什么尺寸:

CGRectMake(x-origin, y-origin, width, height); 

以下是获取当前方向的基准:

http://www.ddeville.me/2011/01/getting-the-interface-orientation-in-ios/

更改视图框的尺寸相对简单并可以在苹果的文档或一些简单的谷歌搜索中找到。

+0

不工作。我已经把这些代码放回原处,并接受所有的方向,但它只能显示肖像 – dimirc 2012-07-24 00:53:48

相关问题