8

我有一个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)];
}

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

4

1 回答 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];
于 2013-04-15T20:17:12.660 回答