[英]Any way to present navigation bar for UIImagePickerController, source type UIImagePickerControllerSourceTypeCamera, in iOS 7?
In iOS 6, I was using the following code to push a UIImagePickerController
, of source type UIImagePickerControllerSourceTypeCamera
, and to show its navigation bar. 在IOS 6,I使用以下代码来推动UIImagePickerController
,源类型的UIImagePickerControllerSourceTypeCamera
,并显示其导航栏。 I wanted to show the navigation bar because after taking the image, I'm pushing another VC that allows the user to set some attributes in the database. 我想显示导航栏,因为在拍摄图像后,我正在推送另一个VC,允许用户在数据库中设置一些属性。
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
cameraController = [[UIImagePickerController alloc] init];
cameraController.delegate = self;
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:cameraController animated:YES completion:NULL];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
cameraController.topViewController.title = @"Add";
cameraController.navigationBar.translucent = NO;
cameraController.navigationBar.barStyle = UIBarStyleDefault;
[cameraController setNavigationBarHidden:NO animated:NO];
}
In iOS 7 this code no longer shows the navigation bar. 在iOS 7中,此代码不再显示导航栏。 Does anyone know if there's a way to to get the navigation bar back for UIImagePickerController
, of source type UIImagePickerControllerSourceTypeCamera
? 有没有人知道是否有办法让UIImagePickerController
获取导航栏,源类型为UIImagePickerControllerSourceTypeCamera
?
Guess what? 你猜怎么着? When imagePicker presents, it's automatic set to hidden.... 当imagePicker出现时,它会自动设置为隐藏....
All you need to do is setHidden:NO in next runloop. 您需要做的就是setHidden:下一个runloop中的NO。 Like: 喜欢:
[self presentModalViewController:imagePicker animated:YES];
[self performSelector:@selector(showNavigationBar:) withObject:imagePicker afterDelay:0];
- (void)showNavigationBar:(UIImagePickerController*)imagePicker {
[imagePicker setNavigationBarHidden:NO];
}
@LeverkusenFan's solution works well. @LeverkusenFan的解决方案效果很好。 But instead of using a hack such as a run loop, you use the completion handler of presentViewController to achieve that effect. 但是,不使用诸如运行循环之类的hack,而是使用presentViewController的完成处理程序来实现该效果。
[self presentViewController:cameraController animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
cameraController.topViewController.title = @"Add";
cameraController.navigationBar.translucent = NO;
cameraController.navigationBar.barStyle = UIBarStyleDefault;
[cameraController setNavigationBarHidden:NO animated:NO];
}];
In fact a better solution that avoids the weird animation when the navigation bar shows up and which works well when you press the back button on the nav bar is as follows: 事实上,一个更好的解决方案,当导航栏出现时避免奇怪的动画,并且当你按下导航栏上的后退按钮时,它可以很好地工作如下:
In the delegate for the UIImagePickerController implement the following function. 在UIImagePickerController的委托中实现以下功能。
- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (navigationController == self.cameraController && navigationController.viewControllers.count == 1) {
// When showing the ImagePicker update the status bar and nav bar properties.
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
navigationController.topViewController.title = self.cameraTitle;
navigationController.navigationBar.translucent = NO;
navigationController.navigationBar.barStyle = UIBarStyleDefault;
[navigationController setNavigationBarHidden:NO animated:animated];
}
}
This function will get called when the ImagePicker is shown and we only make the changes for the rootViewController of the ImagePicker (ie the camera screen). 显示ImagePicker时将调用此函数,我们只对ImagePicker的rootViewController(即摄像头屏幕)进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.