2014-01-28 44 views
2

我需要拍照Ÿ试试这个当删除状态栏而不是工作删除状态栏编程7

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

回答

0

在presentViewController完成块的设置状态栏隐藏在dismissviewcontroller的完成。如果你想隐藏完全在状态栏为此取消隐藏状态栏

+0

不起作用=(和尝试这个“[自我presentViewController:self.imagePicker动画:是完成:^ { [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];}];“ – Fabio

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; 
} 
+2

我尝试但不工作=( – Fabio

+0

也尝试过但没有工作 –

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

我的开发环境:6.6.1的XCode上约塞米蒂10.10.1,适用于iOS 8.1