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

时间:2014-01-28 18:03:01

标签: ios ios7 uiimagepickercontroller statusbar

我需要在拍照时删除状态栏,试试这个但不能正常工作

[[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];
}

3 个答案:

答案 0 :(得分:3)

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

- (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;
}

答案 1 :(得分:1)

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

- (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

答案 2 :(得分:0)

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