【问题标题】:Gap between Navigation bar and view controller content导航栏和视图控制器内容之间的差距
【发布时间】:2014-02-17 09:22:06
【问题描述】:

我要在导航栏和视图控制器内容之间的间隙中创建“无连接”视图。

我想继承 UINavigationViewController 并将视图控制器的内容向下移动一点。

问题是如何以正确的方式做到这一点?

我目前的解决方案是有效的,但它也很老套。我想让它变得更好。

// subclass of AGNavigationController
-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    static BOOL firstTime = YES;
    if (firstTime) {
        contentView = nil;
        for (UIView *v in self.view.subviews) {
            if ([v isKindOfClass:[NSClassFromString(@"UINavigationTransitionView") class]]) {
                contentView = v;
                break;
            }
        }
        firstTime = NO;
        origFrame = contentView.frame;
        noConnectionView.frame = CGRectMake(0, self.navigationBar.frame.origin.y+self.navigationBar.frame.size.height, 320, 20);
    }
    [self adjustToConnection:NO withAnimation:NO];
}

-(void)adjustToConnection:(BOOL)isConnection withAnimation:(BOOL)animation {
    if (isConnection) {
        [noConnectionView removeFromSuperview];
        contentView.frame = origFrame;
    } else {
        [self.view addSubview:noConnectionView];
        contentView.frame = CGRectMake(0, origFrame.origin.y+20, 320, origFrame.size.height-20);
    }
}

【问题讨论】:

    标签: ios objective-c uiviewcontroller uinavigationcontroller


    【解决方案1】:

    创建您的UIView 并将其框架设置为类似(0, 0, self.view.frame.size.witdh, 40)

    使用[self.view addSubview:myView]; 将视图添加到您的UIViewController

    在主视图中向下移动元素,垂直偏移设置为myView.frame.size.height

    这就是像这样的问题你所能得到的。如果您需要更多帮助,您必须更准确地说明您尝试了什么,什么不起作用。

    【讨论】: