我有一个在 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 调整大小以适应新的可用空间(我不想手动执行)。