一般来说UINavigationController是作为UIWindow的子view来使用的,例如当你创建一个Navigation类型的应用程序时,系统会将AppDelegate中的navigationController做为window的根控制器
self.window.rootViewController = self.navigationController; [self.window.makeKeyAndVisible];
UINavigationController在放置自己的位置时,会默认考虑到状态条,并在顶部留出20px的空白位置。
但是当将一个UINavigationController放到一个UIViewController中作为子view控制器存在时,这个白条就让人心烦了。
层级关系如下
UIWindow
- UIViewController
- UINavigationController
要处理这个恼人的白条,只要在UIViewController的继承类的viewDidLoad函数中增加一句话就可以了。
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - ( void )viewDidLoad { [super viewDidLoad]; [_navController.view setFrame: [self.view bounds]]; [self.view addSubview:_navController.view]; }=================================================================================================================================1、navigationControll = [[UINavigationController alloc] init]; navigationView = [[UIViewController alloc] initWithNibName:@"XXXViewController" bundle:nil]; 。。。。。。 [navigationControll pushViewController:navigationView animated:YES]; [self presentModalViewController:navigationControll animated:YES];2、向已有的UIViewController中添加UINavigationController
3、
假设你的代码模型是这样的: MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease]; [self presentModalViewController:vc animated:YES]; 那就这样做就可以了: MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease]; UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease]; [self presentModalViewController:navController animated:YES]; [self.view setFrame:CGRectMake(0,0,320,480)];加上这句