允许一个视图支持多个方向,而其他视图则不支持 iPhone

发布于 2024-11-02 10:00:47 字数 235 浏览 2 评论 0原文

我遇到的情况是,我有多个视图通过 UITabBarController 控制。其中一个视图是通过 UINavigationController 控制的。应用程序应该只支持所有视图的纵向...除了一个单独的视图。该视图被推送到导航控制器的堆栈上,并且应该允许纵向和横向。

我已经尝试了我能想到的所有解决方案,但是,要么该解决方案不起作用,要么更糟糕的是完全无法预测。

有人以干净的方式解决这个问题吗?

I have a situation where I have multiple views controlled via UITabBarController. One of those views is controlled via a UINavigationController. The application should only support Portrait for all views... except one single solitary view. This view is pushed onto the stack of the navigation controller and should allow both portrait AND landscape.

I've tried every solution that I can think of but, either the solution just doesn't work or worse is completely unpredictable.

Has anybody solved this issue in a clean way?

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

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

发布评论

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

评论(4

熟人话多 2024-11-09 10:00:48

使用 presentModalViewControllerpushViewController 呈现的视图控制器应该支持任何方向,使用此方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

使用此方法,当您以横向方向呈现控制器时,它将正确也以横向方式出现。

The view's controller that you present either using presentModalViewController OR pushViewController should support any orientation, using this method:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

With this method, when you present your controller in landscape orientation, it will correctly appear in landscape orientation, too.

不甘平庸 2024-11-09 10:00:48

我也有同样的问题。您必须为您的 UITabBarController 实现 shouldAutorotateToInterfaceOrientation: ,并为您希望在所有视图控制器中支持的所有方向返回 YES。在相同的方法中,对于所有其他视图控制器,仅对于您想要在每个视图控制器中支持的方向返回 YES。

要为 UITabBarController 实现 shouldAutorotateToInterfaceOrientation:,您可以子类化 UITabBarController,但更简单的方法是在 UITabBarController 上实现一个类别并仅实现该方法:

@implementation UITabBarController(orientation)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation
{
    return YES; // or whatever you need
}

@end

注意:在 Web 浏览器中键入;未编译。 :-)

您可以将其放在应用程序委托 .m 文件末尾。

我发现 UITabBarController 仅针对纵向返回 YES,这显然也会影响所有从属视图控制器。就我而言,我有一个从属视图控制器,我想支持纵向和横向,这解决了这个问题。

I had the same problem. You have to implement shouldAutorotateToInterfaceOrientation: for your UITabBarController and return YES for all the orientations you want to support across all your view controllers. And in the same method for all the other view controllers return YES only for the orientations you want to support in each of those view controllers.

To implement shouldAutorotateToInterfaceOrientation: for your UITabBarController, you could subclass UITabBarController, but an easier way is to implement a category on UITabBarController and just implement that method:

@implementation UITabBarController(orientation)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation
{
    return YES; // or whatever you need
}

@end

NB: Typed into a web browser; not compiled. :-)

You can put this right in your app delegate .m file at the end.

What I found was that UITabBarController returns YES only for portrait, which apparently also affects all the subordinate view controllers. In my case I had one subordinate view controller that I wanted to support both portrait and landscape and this solved it.

轻许诺言 2024-11-09 10:00:48

如果您在选项卡栏内有导航,则唯一的选择是将特定视图呈现为模式视图(选项卡栏要求所有视图支持自动旋转方向)。因此,基本上需要横向的单视图控制器应该实现

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
          // Create the landscape version of the view and present it modally
      }

      return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

然后通过检测纵向方向并使用父级的方法,在模态视图控制器的相同方法中关闭模态视图[self.parentViewController解雇ModalViewControllerAnimated:动画]

If you have the navigation inside of a tab bar, then the only option is to present the particular view as a modal view (tab bar requires all views to support the orientation to autorotate). So basically the single view controller, that needs landscape should implement

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
          // Create the landscape version of the view and present it modally
      }

      return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Then dismiss the modal view in the modal view controller's same method, by detecting portrait orientation and using the method for the parent [self.parentViewController dismissModalViewControllerAnimated: animated]

聚集的泪 2024-11-09 10:00:48

对于iOS-6,我已经这样做了,它运行得很好

(NSUInteger)supportedInterfaceOrientations
{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{ 
    return UIInterfaceOrientationLandscapeLeft;
}

这会对你有帮助......

For iOS-6 , I have done this , it is running greatly

(NSUInteger)supportedInterfaceOrientations
{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}

(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{ 
    return UIInterfaceOrientationLandscapeLeft;
}

This will help you....

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