ios – 向UINavigationController添加自定义视图

前端之家收集整理的这篇文章主要介绍了ios – 向UINavigationController添加自定义视图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个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)];
}

这是解决这个问题的方法吗?

解决方法

- (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,40.0)]){
       self.navController = navController;
      }
    return self;
   }

然后

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

猜你在找的iOS相关文章