【问题标题】:Restricting supported orientation to specific storyboard in multi storyboard app [closed]在多故事板应用程序中将支持的方向限制为特定故事板[关闭]
【发布时间】:2014-02-23 14:29:55
【问题描述】:

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

提前致谢。

【问题讨论】:

  • 为什么是多故事板?更多关于多故事板的细节请...
  • @FahimParkar:因为我想要单独的故事板用于单独的模块。这被认为是我希望的最佳实践。
  • 我会说多个故事板是个坏主意,因为它会使应用程序变得繁重并且编译/运行需要更多时间......
  • 检查我的答案...希望这是您需要的...
  • 请添加代码的基本部分。

标签: ios ios7 storyboard xcode5 uistoryboard


【解决方案1】:

你想要什么都可以做...(以下是应用程序仅横向的示例)

创建自定义导航控制器

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    相关资源
    最近更新 更多