限制多故事板应用程序中特定故事板的支持方向

时间:2014-02-23 14:29:55

标签: ios ios7 storyboard xcode5 uistoryboard

我的应用程序中有多个故事板,我希望将故事板方向保持为纵向。 有可能吗?如果是的话怎么样?

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以做什么...(以下是仅适用于横向广告的示例)

创建自定义导航控制器

CustomNavigationController.h

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;

@end

CustomNavigationController.m

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


- (NSUInteger)supportedInterfaceOrientations
{
    if (![[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"ViewController")])
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    else
    {
        return [self.topViewController supportedInterfaceOrientations];
    }
}

在您只想要横向的所有文件中包含以下内容...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"1. shouldAutorotateToInterfaceOrientation");
    if (interfaceOrientation==UIInterfaceOrientationMaskPortrait) {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    ||(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationLandscapeLeft;
}

- (BOOL)shouldAutorotate
{
    return YES;
}