导航栏和视图控制器内容之间的差距

时间:2014-02-17 09:22:07

标签: ios objective-c uiviewcontroller uinavigationcontroller

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

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

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

我目前的解决方案正在运作,但它也非常hacky。我想让它变得更好。

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

1 个答案:

答案 0 :(得分:0)

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

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

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

这就是你能得到的这样一个问题。如果您需要更多帮助,您必须更准确地了解您尝试过的内容以及哪些内容无效。