在 imagePickerController IOS 7 中以编程方式删除状态栏

Posted

技术标签:

【中文标题】在 imagePickerController IOS 7 中以编程方式删除状态栏【英文标题】:Remove status bar programmatically in imagePickerController IOS 7 【发布时间】:2014-02-20 04:56:47 【问题描述】:

我需要在拍照时删除状态栏你试试这个但不起作用

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

- (IBAction)botonCamara:(id)sender 


    // Make sure camera is available
    if ([UIImagePickerController
         isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:@"Camera Unavailable"
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:nil, nil];
        [alert show];
        return;
    
    if (imagePicker == nil)
    
        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.allowsEditing = YES;
    
    [self presentViewController:imagePicker animated:YES completion:NULL];



#pragma mark - delegate methods

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info


    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    UIImageWriteToSavedPhotosAlbum (image, nil, nil , nil);

    [self dismissViewControllerAnimated:YES completion:NULL];

【问题讨论】:

【参考方案1】:

如果您想完全隐藏状态栏,请执行此操作

- (void)viewDidLoad

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) 
        // ios 7
        [self prefersStatusBarHidden];
        [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
     else 
        // iOS 6
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    


// Add this Method
- (BOOL)prefersStatusBarHidden

    return YES;

【讨论】:

【参考方案2】:

我尝试了很多方法,我认为这是以编程方式隐藏状态栏的最简单方法。

- (void)showStatusBar 
    UIWindow *statusBarWindow = [(UIWindow *)[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
    CGRect frame = statusBarWindow.frame;
    frame.origin.y = 0;
    statusBarWindow.frame = frame;

- (void)hideStatusBar 
    UIWindow *statusBarWindow = [(UIWindow *)[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
    CGRect frame = statusBarWindow.frame;
    CGSize statuBarFrameSize = [UIApplication sharedApplication].statusBarFrame.size;
    frame.origin.y = -statuBarFrameSize.height;
    statusBarWindow.frame = frame;
 

我的开发环境:Yosemite 10.10.1 上的 XCode 6.6.1,适用于 iOS 8.1

【讨论】:

【参考方案3】:

在presentViewController完成块中设置状态栏隐藏,在dismissviewcontroller的完成中取消隐藏状态栏

【讨论】:

不工作 =( 试试这个 " [self presentViewController:self.imagePicker animated:YES completion:^[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];]; "

以上是关于在 imagePickerController IOS 7 中以编程方式删除状态栏的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 ImagePickerController 直接显示“相机胶卷”

无法获取 UIImage 以匹配自定义 ImagePickerController 预览

imagePickerController 获取图片的拍照时间等信息

imagePickerController 返回 0 字节的图像

在 imagePickerController IOS 7 中以编程方式删除状态栏

如何将带有 imagepickercontroller 的照片作为缩略图放入 collectionView 单元格