在UITabBarController中强制特定的viewcontroller在landscape中

问题描述 投票:0回答:3

我在UITabBarController中有5个导航控制器。 UITabBarController中的一个Navigationcontroller有一个Viewcontroller总是将其他所有肖像都映射到..

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

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

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

上面的代码我放在NavigationController子类中。

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

上面的代码我放入了Landscape Controller。

我有Base作为UIViewController子类,我把这个代码

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([self isKindOfClass:[LanscapeViewController class]])
        return UIInterfaceOrientationLandscapeLeft;
    else
        return UIInterfaceOrientationPortrait;
}

如果我提出那个viewcontroller它很好地显示屏幕只有景观。但是,如果我将ViewController推送到Portrait中的遗骸中。

ios objective-c uitableview uinavigationcontroller uiinterfaceorientation
3个回答
1
投票

您是否在ViewController中为Portrait Mode编写了下面的代码。

    -(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortraitUpsideDown | UIInterfaceOrientationPortrait;
}

0
投票

看看这篇文章。分别是http://www.klecker.de/photo/index.php?option=com_content&task=view&id=148&Itemid=213Presenting Navigation Controller in Landscape mode is not working ios 6.0

我在标签栏应用程序中这样做了,但我没有强制旋转其中一个选项卡的直接根视图控制器,但是它的一个子视图。我不确定这是否适用于标签栏的一个视图控制器。


0
投票

创建一个UIViewController类别来检查当前的ViewController,

#import <UIKit/UIKit.h>

@interface UIViewController (Utils)

+(UIViewController*) currentViewController;

@end

#import "UIViewController+Utils.h"

@implementation UIViewController (Utils)

+(UIViewController*) findBestViewController:(UIViewController*)vc {

    if (vc.presentedViewController) {

        // Return presented view controller
        return [UIViewController findBestViewController:vc.presentedViewController];

    } else if ([vc isKindOfClass:[UISplitViewController class]]) {

        // Return right hand side
        UISplitViewController* svc = (UISplitViewController*) vc;
        if (svc.viewControllers.count > 0)
            return [UIViewController findBestViewController:svc.viewControllers.lastObject];
        else
            return vc;

    } else if ([vc isKindOfClass:[UINavigationController class]]) {

        // Return top view
        UINavigationController* svc = (UINavigationController*) vc;
        if (svc.viewControllers.count > 0)
            return [UIViewController findBestViewController:svc.topViewController];
        else
            return vc;

    } else if ([vc isKindOfClass:[UITabBarController class]]) {

        // Return visible view
        UITabBarController* svc = (UITabBarController*) vc;
        if (svc.viewControllers.count > 0)
            return [UIViewController findBestViewController:svc.selectedViewController];
        else
            return vc;

    } else {

        // Unknown view controller type, return last child view controller
        return vc;

    }

}

+(UIViewController*) currentViewController {

    // Find best view controller
    UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    return [UIViewController findBestViewController:viewController];

}

@end

Appdelegate.m导入上面的UIViewcontroller类别,导入要在Landscape中显示的ViewController并实现方向方法

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([[UIViewController currentViewController] isKindOfClass:[YourLandScapeViewController class]]) {

        return UIInterfaceOrientationMaskLandscape; //Orientation for LandScapeViewcontroller

    }
    return UIInterfaceOrientationMaskPortrait; // rest All ViewController
}
© www.soinside.com 2019 - 2024. All rights reserved.