iPad IOS5定位

时间:2012-06-25 15:41:16

标签: ipad

我目前正在iPad上开发应用程序。它仅支持纵向方向,但不支持横向。应该在.m文件中编辑或添加哪些代码(什么文件)以使其支持剩余的格局?我需要应用程序中的所有页面来支持它。

2 个答案:

答案 0 :(得分:1)

每个UIViewController都需要实现此方法:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

如果你只想支持几个(只要你不希望得到任何支持就返回NO):

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    //Allow Original Portrait
    if(interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        return YES;
    }
    //Allow Upside Down
    else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        return YES;
    }
    //Allow Landscape Left
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        return YES;
    }
    //Allow Landscape Right
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        return YES;
    }
}

答案 1 :(得分:0)

在每个视图控制器中,您需要添加以下代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    
    return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOritentationPortraitUpsideDown));
 }
相关问题