自动旋转标签栏应用程序

时间:2011-03-01 16:38:30

标签: objective-c cocoa xcode uiinterfaceorientation autorotate

嘿伙计们, 我正在尝试自动旋转我的Tab Bar应用程序。显然,我知道大多数人都会对这个问题说return YES;或者所有Tab Bar项必须在同一个类中才能自动旋转。不,它对我不起作用。首先,我有4个Tab Bar项目,每个项目都有自己的Classes。我的前两个标签栏项目有UIWebViews,第二个是表视图,最后一个是带按钮的图像视图。现在我练习为我的第一个Tab Bar Item实现自动旋转代码,这是一个使用此代码的UIWebView,因为return YES;对我不起作用:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations.
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
        if (interfaceOrientation == UIInterfaceOrientationPortrait ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight)
            return YES;
        else
            return NO;
}

使用没有Tab Bar的代码对我有用,但是当使用Tab Bar应用程序时,它对我来说不起作用。当程序员告诉我让所有其他Tab Bar应用程序必须具有相同的Class文件时,我不能这样做,因为我的每个Tab Bar都有自己的Class文件,正如我之前所说的那样。

所以希望有人可以帮我解决这个问题,以便自动旋转整个标签栏,谢谢

2 个答案:

答案 0 :(得分:3)

您需要在标签栏中的所有视图控制器上返回YES


此外,您的代码可以更短,只需:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

答案 1 :(得分:1)

你知道你在第一行中返回YES(如果是纵向)或者这个方法是NO?

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations.
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    // this never gets called:
    //    if (interfaceOrientation == UIInterfaceOrientationPortrait ||
    //        interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    //        interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    //        return YES;
    //    else
    //        return NO;
}
相关问题