iOS UINavigationBar向下移动视图

iOS UINavigationBar向下移动视图,ios,resize,uinavigationbar,Ios,Resize,Uinavigationbar,我有一个在UINavigationController中使用的视图,它会自动向下推以按预期安装窗口。但是,我需要显示与模型相同的视图,并且它没有UINavigationController(或需要一个),因此我只添加了一个UINavigationBar,如下所示: if (presentedAsModal == YES) { UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake

我有一个在UINavigationController中使用的视图,它会自动向下推以按预期安装窗口。但是,我需要显示与模型相同的视图,并且它没有UINavigationController(或需要一个),因此我只添加了一个UINavigationBar,如下所示:

if (presentedAsModal == YES) {
    UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    [self.view addSubview:navigationBar];

    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
    style:UIBarButtonSystemItemDone target:nil action:@selector(dismissModalViewControllerAnimated:)];

    UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];
    item.leftBarButtonItem = leftButton;
    item.hidesBackButton = YES;
    [navigationBar pushNavigationItem:item animated:NO];

    [[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:0/255.0f green:180/255.0f blue:220/255.0f alpha:1.f]];
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:0/255.0f green:140/255.0f blue:180/255.0f alpha:1.f]];
    }

然而,navigationBar不会自动按下VC,它最终会覆盖我的部分视图。添加导航栏后,是否有办法使VC调整大小以适应新的可用空间(我不想手动执行此操作)

您可以将vc嵌入导航控制器中,以进行模式演示,也可以修改边界原点:

CGRect bounds = self.bounds;
bounds.origin.y = -44;
self.bounds = bounds;
...
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, -44, 320, 44)];
...

这是可行的,我希望有一个干净的财产,我可以实现这一点,但我想不是吗?我知道我可以把它放在NavController中,但考虑到我不需要NavController,只需要“查看/返回”按钮栏,这似乎是错误的。导航控制器在将视图添加到视图之前会使视图变小,因此没有“导航栏收缩行为”。导航栏是一个视图/控件,与其他所有内容一样