【问题标题】:Set width of UINavigationController loaded from storyboard设置从情节提要加载的 UINavigationController 的宽度
【发布时间】:2013-05-09 18:31:03
【问题描述】:

我正在为 iPad 应用程序使用 ECSlidingViewController,我正在尝试获取 UINavigationController 作为母版页(菜单),它将在主 UIViewController 的左侧显示。

要做到这一点,UINavigationCONtroller 需要一个特定的宽度,否则它会变成不需要的全宽。

我正在使用情节提要并像这样加载视图控制器:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Setup the view controllers
    self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainTop"];    
    self.underLeftViewController  = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}

如何将其宽度限制为 320 像素?我知道我必须设置框架,它只是在哪里以及如何设置。

【问题讨论】:

  • 导航控制器不能只嵌入leftviewcontroller吗?
  • 是的,这就是我想要做的,但要让它只有 320px 宽,它默认为全宽

标签: uiview uinavigationcontroller storyboard


【解决方案1】:

好的,一旦我想到它,这实际上很容易。我确保我的菜单视图控制器嵌入在情节提要的 UINavigationController 中。从菜单 VC 中移除 storyboardID 并将其添加到 UINavigationController。

然后我继承了 UINavigationController 并将以下内容添加到 viewDidLoad 方法中:

- (void)viewDidLoad
{
    [super viewDidLoad]; 

    [self.slidingViewController setAnchorRightRevealAmount:320.0f];
    self.slidingViewController.underLeftWidthLayout = ECFixedRevealWidth;

}

从原始菜单 VC viewDidLoad 方法中删除该代码。阅读 ECSlidingViewController 添加 ECFixedReveal 的文档将调整 VC 的大小以匹配 setAnchorRightRevealAmount 值。

现在我在显示的左侧菜单中有一个导航控制器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 2019-01-08
    相关资源
    最近更新 更多