我有一个信息按钮作为我的UIImagePickerController
的自定义叠加的一部分。单击它时,我设置导航栏的外观(在UIImagePickerController
“演示文稿”中隐藏)并推送一个新的视图控制器:
- (IBAction)infoButtonPressed:(id)sender {
CameraHelpViewController *helpController = [[[CameraHelpViewController alloc] initWithNibName:@"CameraHelpViewController" bundle:nil] autorelease];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[ipc pushViewController:helpController animated:NO];
}
CameraHelpViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Web view loading
NSString *basePath = [[NSBundle mainBundle] resourcePath];
basePath = [basePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
basePath = [basePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *HTMLfile =[[NSBundle mainBundle] pathForResource:@"camera_help" ofType:@"html"];
NSError *error;
NSString *stringFromPath = [[[NSString alloc] initWithContentsOfFile:HTMLfile encoding:NSUTF8StringEncoding error:&error] autorelease];
[webView loadHTMLString:stringFromPath baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//", basePath]]];
webView.backgroundColor = [UIColor blackColor];
webView.opaque = NO; // Prevents the white flash from occurring
[_activityIndicator startAnimating];
}
//UPDATE:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
自使用@ryancrunchi代码后更新,导航栏按钮不会移动到视图中。相反,导航栏在视图加载后向上移动几秒钟。
我想在新视图出现之前完全设置导航栏。我怎样才能做到这一点?
使用这些线:
[ipc setNavigationBarHidden:NO animated:YES];
[ipc pushViewController:helpController animated:NO];
你动画导航栏,但你展示你的helpController
没有动画。所以helpController
出现在导航栏之前,导航栏本身正在播放动画(延迟显示)。如果您根本不想要动画,请将[ipc setNavigationBarHidden:NO animated:NO];
放入CameraHelpViewController
:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[ipc setNavigationBarHidden:NO animated:animated];
// or
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
当视图消失时隐藏栏:
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[ipc setNavigationBarHidden:YES animated:animated];
// or
[self.navigationController setNavigationBarHidden:YES animated:animated];
}