0

我希望我的所有视图都处于纵向模式。这有效,除非我将 a 推UINavigationController到另一个上。在这种情况下,内部的视图secondaryNavigationController将遵循设备方向。这是我如何调用UINavigationControllers.

[secondaryNavigationController setNavigationBarHidden:YES];
[[appDelegate secondaryNavigationController navigationBar] setHidden:YES];
[mainNavigationController presentModalViewController:[appDelegate secondaryNavigationController] animated:YES];

我所有的观点都实现了这个方法,但它似乎没有帮助。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
4

2 回答 2

1

小心:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

由于它已在 iOS 6.0 上被弃用。目前这里有一些UIViewControllers内部旋转的问题UINavigationControllers,或者UITabBarControllers。为了解决这个问题,在您的情况下,您应该对它进行子类化UINagivationController或为其创建一个类别(尽管 Apple 不鼓励第二个而不是第一个)。您可以使用(这种情况是针对 a 的UITabBarController,但您可以理解逻辑)来检查如何进行子分类。然后,您可以为您执行以下操作UIViewControllers

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

尽管您允许旋转(返回 YES),但它UIViewController始终是纵向的。这里的逻辑是,如果您来自UIViewControllerLandscape,如果您返回 NO,您的UIViewController, 将留在 Landscape。

于 2012-11-15T07:34:49.313 回答
0

这是对我有用的完整答案,基于 iYaniv 的评论和 Jacky Boy 的答案。

我采用了 iYaniv 的类别并将其作为子类UINavigationController而不是类别(这是您应该做的)。UINavigationController *然后我用替换了所有实例myUINavigationController *。然后在我所有的UIViewControllers.

/* myUINavigationController.h */

#import <UIKit/UIKit.h>

@interface myUINavigationController : UINavigationController

@end

/* myUINavigationController.m */

#import "myUINavigationController.h"

@interface myUINavigationController ()

@end

@implementation myUINavigationController

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end
于 2012-12-02T03:32:35.863 回答