iOS和View iOS中的View Controller [英] View Controllers in view Controller and orientation iOS

查看:64
本文介绍了iOS和View iOS中的View Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPAD应用程序,该应用程序具有UIViewController A作为Navigation Controller的根视图Controller.现在,我还有3个视图控制器B,C,D作为ViewController A的子视图.

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.

我希望B不响应方向,而C和D应该响应方向.

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.

还有另一个答案,说制作两个单独的根ViewController并将它们添加到Windows View中.其中一个不旋转,另一个不旋转.我之所以不能这样做,是因为我在ViewController A中具有标头,该标头可以切换B,C,D使其位于viewController的前面.

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.

谢谢

推荐答案

您需要像这样对UINavigationController进行子类化.

You need to subclass the UINavigationController like this.

.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

这篇关于iOS和View iOS中的View Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆