将iphone转换为ipad,但在旋转ipad时屏幕不会自动旋转

时间:2012-04-23 15:51:39

标签: iphone ios

我将基于tabbar的iphone应用程序转换为ipad版本与不同的~ipo.xib,唯一不同的是ui元素大小。现在我的问题是它不能在ipad版本中自动旋转屏幕,即我颠倒了ipad,但ui不会颠倒旋转。

4 个答案:

答案 0 :(得分:4)

对于标签栏中显示的所有视图控制器,您需要为shouldAutorotateToInterfaceOrientation:返回YES,仅适用于iPad(UI_INTERFACE_IDIOM()...)。如果是肖像,则iPhone控制器的默认代码可能仅返回YES,如果这是您在最初创建项目时选择的全部内容。

以下是我用于此情况的代码(iPhone,仅限肖像,iPad,所有方向):

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return YES;
    else
        return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}

答案 1 :(得分:2)

标签栏控制器无法自动旋转。你必须旋转所有组件。

答案 2 :(得分:1)

如果是通用应用,您可以使用此代码完成任务

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    BOOL ret;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        // iPad-specific code

    if (interfaceOrientation != UIInterfaceOrientationPortrait) {
        ret = YES;
    }else{
        ret = NO;
    }
    } else  {
        // iPhone-specific code

    ret = YES;
    }

 return ret;

}

答案 3 :(得分:0)

您需要修改“支持的设备方向”以包含新的方向

相关问题