Tabbar Nav 应用程序,允许一个视图旋转,而其他视图则不旋转

发布于 2024-09-07 23:41:13 字数 1269 浏览 3 评论 0原文

我有一个选项卡栏应用程序,其中有 3 个不同的视图,每个视图都有自己的视图控制器。

在选项卡条形码中,我有这个来处理旋转。

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
 }
@end

然后在我想根据设备方向旋转的第二个视图控制器中:

// Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   return YES;
 }

对于我不想旋转的其他两个视图,我设置了此方法。

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

问题:所以这在视图 1 和视图 3 中工作得很好,当你旋转设备时,它们保持在纵向模式,这是所需的。当在视图 2 中我旋转到横向时,视图按预期旋转并旋转到横向。但是,当在视图 2 中处于横向模式时单击视图 1 或视图 3 选项卡时,视图 1 和视图 3 处于横向模式。

即使视图 2 旋转为横向,我也不知道如何强制它们处于纵向。

有人知道该怎么做吗?

I have a tab bar application in which i have 3 diffrent views each with there own view controller.

In the tab bar code i have this, to handle rotation.

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
 }
@end

Then in the 2nd view controller that i want to rotate depending on device orientation i have:

// Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   return YES;
 }

And For the other two views that i do not want to rotate i have this method set.

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

The PROBLEM: so this works fine in view 1 and view 3 when u rotate the device they stay in portrait mode which is desired. When in view 2 i rotate to landscape, the view does as expected and rotates to landscape. BUT when click view 1 or view 3 tab while in lanscape mode in view 2, View 1 and View 3 are in landscape mode.

I can't figure out how to force them in portrait even if view 2 rotates to lanscape.

Any one know how to do this?

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

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

发布评论

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

评论(1

妖妓 2024-09-14 23:41:13

从 2008 年到现在,对此有一个大讨论[1](看看几页下面的评论)——总之,它看起来像

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

将让你强制它横向——当用户以编程方式返回您的风景视图。

[1] 横屏模式下的 iPhone 应用,2008 系统

There's a big discussion[1] on this dating back from 2008 until now (look at comments down a few pages) -- summarily it seems like

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

or

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

or

[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

will let you force it to landscape -- you would want to do this when the user goes back to your landscapey view(s) programmatically.

[1] iPhone app in landscape mode, 2008 systems

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