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

查看:1003
本文介绍了如何在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:

'查看基于控制器的状态栏外观'并设置为NO。

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

如果希望状态栏重新出现在其他视图控制器中并且只在特定VC上隐藏,则在VC加载时将状态栏设置为隐藏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天全站免登陆