1

嘿伙计们,我正在尝试自动旋转我的标签栏应用程序。显然,我知道大多数人会说这个问题是return YES;或者所有标签栏项目必须在同一个类中才能自动旋转。不,它对我不起作用。所以首先,我有 4 个标签栏项目,每个项目都有自己的类。我的前 2 个标签栏项目有 UIWebViews,第二个是表格视图,最后一个是带有按钮的图像视图。现在我练习为我的第一个选项卡栏项实现自动旋转代码,这是一个使用此代码的 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 应用程序必须具有相同的 Class 文件时,我不能这样做,因为我的每个 Tab Bar 都有自己的 Class 文件,正如我之前所说的。

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

4

2 回答 2

3

您需要返回选项卡栏中YES所有视图控制器。


您的代码也可以更短,就是这样:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
于 2011-03-01T16:41:07.427 回答
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;
}
于 2011-03-01T17:12:20.390 回答