向UINavigationController添加自定义视图

9
我有一个UINavigationController,当事件被触发时,我需要一个自定义的UIView出现在NavigationBar的下方,但不会遮挡当前的ViewController。我还需要使UIView持久存在,因为控制器正在被推入/弹出。
 -----------------
|   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)];
}

这是正确的做法吗?


请尝试使用此链接 https://github.com/tursunovic/DMRNotificationView - Paras Gandhi
1个回答

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];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接