如何在 UIImagepickercontroller 中隐藏状态栏? [英] How to hide status bar in UIImagepickercontroller?

查看:15
本文介绍了如何在 UIImagepickercontroller 中隐藏状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发的新手.我试图在 UIImagePickerController 中隐藏状态栏.每当我单击拍照"时,都会出现状态栏.它不会隐藏.我希望状态栏仅在 UIImagePickerController 中隐藏.

I am new to iOS development. I am trying to hide status bar in UIImagePickerController. Whenever I click on "Take photo", status bar appears. It doesn't hide. I want status bar to be hidden only in UIImagePickerController.

这是我的代码,

- (IBAction)takePhoto:(UIButton *)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:NULL];
}


- (void)imagePickerController:(UIImagePickerController *)picker     didFinishPickingMediaWithInfo:(NSDictionary *)info
{   
    [self statusBar:YES];
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imageView.image = chosenImage;
    [picker dismissViewControllerAnimated:YES completion:NULL];

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}


-(void)statusBar:(BOOL)status
{
    [[UIApplication sharedApplication] setStatusBarHidden:status];
}

如何隐藏UIImagePickerController上的状态栏?

推荐答案

我遇到了一个问题,即在 iOS7 中我的状态栏没有被隐藏.我以编程方式隐藏它,它仍然显示在 iOS7 中,但是当在 iOS6 中运行时,状态栏会适当地隐藏.您必须转到 plist 并添加以下内容:

I had an issue where in iOS7 my status bar was not being hidden. I hid it programmatically and it still displayed in iOS7, but when ran in iOS6 the status bar would hide appropriately. You have to go to the plist and add the following:

'view controller-based status bar appearance' 并设置为 NO.

'view controller-based status bar appearance' and set to NO.

如果您希望状态栏重新出现在其他视图控制器中并且仅隐藏在特定 VC 上,那么您可以在 VC 加载时将状态栏设置为 hidden YES.当 VC 消失时,您将隐藏的状态栏设置回 NO.

If you want the status bar to re-appear in other view controllers and only be hidden on a particular VC, then you set the status bar to hidden YES when the VC loads. When the VC will disappear you set the status bar hidden back to NO.

- (void)viewDidLoad
{

    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

}

当控制器消失时,您添加以下内容来设置状态栏,使其不再隐藏并显示在下一个视图中:

and when the controller will disappear you add the following to set the status bar so it is no longer hidden and will display on the next View:

-(void)viewWillDisappear:(BOOL)animated{

     [[UIApplication sharedApplication] setStatusBarHidden:NO];

}

setStatusBarHidden:withAnimation: 如果你想要一些流畅的动画

setStatusBarHidden:withAnimation: if you want some smooth animation

这篇关于如何在 UIImagepickercontroller 中隐藏状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆