自动旋转标签栏应用程序

发布于 2024-10-19 22:04:55 字数 963 浏览 3 评论 0原文

嘿伙计们, 我正在尝试自动旋转我的选项卡栏应用程序。显然,我知道大多数人会说这个问题是 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;
}

在没有选项卡栏的情况下使用此代码对我有用,但是当将其与选项卡栏应用程序一起使用时,它对我不起作用。另外,当程序员对我说所有其他选项卡栏应用程序必须具有相同的类文件时,我不能这样做,因为我的每个选项卡栏都有自己的类文件,正如我之前所说的。

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

Hey guys,
I am trying to auto rotate my Tab Bar application. Apparently, I know most people will say to this problem is return YES; or that all the Tab Bar Items have to be in the same class in order to auto rotate. No. It didn't work for me. So first of all, I have 4 Tab Bar Items, each with it's own Classes. My first 2 Tab Bar Items have UIWebViews, second is a Table View and last is an Image View with buttons. Now I practiced implementing the auto rotate code for my first Tab Bar Item, which is a UIWebView using this code since return YES; didn't work for me:

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

Using this code without a Tab Bar worked for me, but when using this with a Tab Bar application, it didn't work for me. Also when programmers said to me to have all other Tab Bar applications have to have the same Class file, I can't do that because each of my Tab Bars have their own Class file, as I've said before.

So hopefully, someone can help me with this situation in order to auto rotate the entire Tab Bar, thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一向肩并 2024-10-26 22:04:55

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


你的代码也可以更短,只是这样:

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

You need to return YES on all view controllers in the tabbar.


Also your code can be shorter, just this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
与风相奔跑 2024-10-26 22:04:55

您知道您在第一行中从该方法返回 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;
}

you are aware that you return YES (in case of portrait orientation) or NO from this method in the first line?

 - (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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文