在uipopovercontroller被解雇后,状态栏仍然可见

时间:2015-04-27 09:33:29

标签: ios xcode ios8.1

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

- (IBAction)PhotoImportAction:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = NO;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
        [self presentViewController:picker animated:YES completion:nil];
    else
    {
      popover=[[UIPopoverController alloc]initWithContentViewController:picker];
              popover.delegate=self;

        [popover presentPopoverFromRect:PhotoImportButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    }


}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *selectedImage=info[UIImagePickerControllerOriginalImage];
    VisualEffectImageVIew.image=selectedImage;
    BackgroundImageView.image=selectedImage;
    ForegroundImageView.image=selectedImage;
   if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
    {
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
    else
    {

        [popover dismissPopoverAnimated:YES];

  }
}
-(void)viewWillAppear:(BOOL)animated
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}

上面的代码非常简单,一切正常,但viewWillAppear解除UIPopoverController后无法在iPad上工作的方法,所以我们尝试使用popoverControllerDidDismissPopover方法但是statusBar仍然可见。任何解决方案都表示赞赏。

4 个答案:

答案 0 :(得分:0)

在viewdidload中添加以下行

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

并添加新方法

 - (BOOL)prefersStatusBarHidden {
          return YES;
  }

还更改info.plist文件查看基于控制器的状态栏外观“=否

答案 1 :(得分:0)

您没有设置弹出框的代表。请设置并检查委托方法是否有效......

希望有所帮助:)

答案 2 :(得分:0)

从我的代码中我看到的是你没有设置UIPopoverController的delegate。 添加以下行

 popover.delegate = self

在呈现弹出窗口之前。希望这有效。

答案 3 :(得分:0)

根据apple的文档,如果以编程方式解除popoverController,则不会调用popoverControllerDidDismissPopover方法。您可以手动调用popoverControllerDidDismissPopover方法。

[self popoverControllerDidDismissPopover:popoverController];