gpt4 book ai didi

ios - 向 UINavigationController 添加自定义 View

转载 作者:可可西里 更新时间:2023-11-01 03:21:26 25 4
gpt4 key购买 nike

我有一个 UINavigationController,当一个事件被触发时,我需要一个自定义的 UIView 出现在 NavigationBar 的正下方,但不会阻碍当前 ViewController。我还需要使 UIView 在弹出/按下 Controller 时保持不变。

 -----------------
| Status Bar |
-----------------
| Nav Bar |
-----------------
| Custom View |
-----------------
| |
| View Controller |
| |
-----------------

我目前正在让我的 CustomView (UIView) 像这样设置框架:

- (id)initWithNavigationController:(UINavigationController *)navController {
self.navController = navController;
return [self init];
}

- (id)init
{
CGRect viewFrame = self.navController.view.frame;

return [self initWithFrame:CGRectMake(viewFrame.origin.x,
self.navController.navigationBar.frame.origin.y + self.navController.navigationBar.frame.size.height,
viewFrame.size.width,
40.0)];
}

这是解决问题的方法吗?

最佳答案

- (id)initWithNavigationController:(UINavigationController *)navController {
CGRect viewFrame = navController.view.frame;

if (self = [super initWithFrame:CGRectMake(viewFrame.origin.x,
navController.navigationBar.frame.origin.y + navController.navigationBar.frame.size.height,
viewFrame.size.width,
40.0)]){
self.navController = navController;
}
return self;
}

然后

CustomView* _myCustomView = [[CustomView alloc] initWithNavigationController:navigationController];
[navigationcontroller.view addSubview:_myCustomView];

关于ios - 向 UINavigationController 添加自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16019507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com