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