0

I have iPAD app which has UIViewController A as root view Controller of Navigation Controller. Now i have 3 more View Controllers B,C, D as subview of ViewController A.

I want B not to respond orientation while C and D should respond to it.

Currently with code all of them respond to orientation change.

There was another answer which says make two separate root ViewControllers and add them into windows View. One of them non rotating and other rotating. I cant do that because i have header in ViewController A which switches B,C,D to make them front viewController.

Anyway please suggest.

Thanks

4

2 回答 2

1

您需要像这样子类化 UINavigationController。

。H

#import <UIKit/UIKit.h>

@interface UINavigationController (Rotation)

- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;

@end

.M

#import "UINavigationController+Rotation.h"

@implementation UINavigationController (Rotation)

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if ([self visibleViewController] && [[self visibleViewController] isKindOfClass:[B class]]) {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}

@end
于 2013-08-12T11:25:29.740 回答
0

您可以从 UINavigationController 创建子类或为其创建类别。并实现这个方法:

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

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

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

然后,在您的控制器中,您应该使用您想要的方向来实现这些方法。

于 2013-08-12T12:34:49.950 回答