在Camera模式下的UIImagePickerView在iPad上的dismissViewController上显示所有黑色

时间:2022-02-25 15:01:10

I have an application which uses a UIImagePickerView to allow the user to either take a picture with their camera or select one from the camera roll using the UIImagePickerView.

我有一个应用程序使用UIImagePickerView允许用户使用他们的相机拍照或使用UIImagePickerView从相机胶卷中选择一个。

After getting a picture, I present a different dialog on top of the picker using [picker presentViewController:myViewController animated:YES completion:nil].

获得图片后,我使用[picker presentViewController:myViewController animated:YES completion:nil]在选择器顶部显示一个不同的对话框。

If I run my app as an iPhone app (on my iPad), when I dismiss myViewController using [myviewController.presentingViewController dismissViewControllerAnimated:YES completion:nil] it goes back to either showing the CameraRoll or the CameraFeed to take another picture.

如果我将我的应用程序作为iPhone应用程序(在我的iPad上)运行,当我使用[myviewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]关闭myViewController时,它会返回显示CameraRoll或CameraFeed以拍摄另一张照片。

But on the iPad, if I am selecting a picture, it works, but if I am taking a picture using the camera feed, I just get a black screen.

但是在iPad上,如果我选择一张图片,它可以正常工作,但如果我使用相机拍照拍照,我就会得到一个黑屏。

Any idea why?

知道为什么吗?

3 个解决方案

#1


6  

On iPad when you are using sources different than camera feed, you are presenting UIImagePickerController in a popover and you can use it as long as you wish. But when you decide to pick up the source UIImagePickerControllerSourceTypeCamera the picker window is presenting full screen and you have two cases:

在iPad上使用不同于相机源的源时,您将在弹出窗口中呈现UIImagePickerController,您可以根据需要使用它。但是当你决定拿起源UIImagePickerControllerSourceTypeCamera时,选择器窗口呈现全屏,你有两种情况:

  1. If you use your custom controls (showsCameraControls = NO) you can take as much pictures as you want with the same controller.
  2. 如果您使用自定义控件(showsCameraControls = NO),您可以使用相同的控制器拍摄所需的照片。
  3. If you use default controls (showsCameraControls = YES), after taking ONE picture you MUST dissmiss the controller because it is unusable again and I guess this is your case. You are putting the next controller on the stack after taking the photo, after that you are trying to go back to your picker controller but it is unusable any more and you can see the black screen.
  4. 如果您使用默认控件(showsCameraControls = YES),在拍摄一张照片后,您必须关闭控制器,因为它再次无法使用,我猜这是您的情况。你拍摄照片后将下一个控制器放在堆叠上,之后你试图回到拾取器控制器,但它不再可用,你可以看到黑屏。

Apple docs for imagePickerController:didFinishPickingMediaWithInfo: :

imagePickerController的Apple文档:didFinishPickingMediaWithInfo ::

If you set the image picker’s showsCameraControls property to NO and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface. However, if you set that property to YES, your delegate must dismiss the image picker interface after the user takes one picture or cancels the operation.

如果将图像选择器的showsCameraControls属性设置为NO并提供自己的自定义控件,则可以在取消图像选择器界面之前拍摄多张图片。但是,如果将该属性设置为YES,则在用户拍摄一张照片或取消操作后,您的代理人必须关闭图像选择器界面。

If you want to take another picture in this case you have to go back to your base controller and create the UIImagePickerController instance one more.

如果您想在这种情况下拍摄另一张照片,则必须返回基本控制器并再创建一个UIImagePickerController实例。

I hope this will help.

我希望这将有所帮助。

Edit: The easiest way IMO to rebuild your view controllers stack is to dismiss the picker after taking a photo without animation and after that show the next controller with animation. It will give the user feeling, that the next controller is displayed just after the picker controller without any "flashing".

编辑:IMO重建视图控制器堆栈的最简单方法是在拍摄没有动画的照片后关闭选择器,之后显示下一个带动画的控制器。它会让用户感觉,下一个控制器就会在拾取器控制器之后显示而没有任何“闪烁”。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:NO completion:^{
        [self presentViewController:<newController> animated:YES completion:nil];
    }];
}

#2


1  

You can try dismiss normally the UIImagePicker, and when the Pre-viwer View Controller activate viewWillDesapear, you "say" to the previous viewController that when it viewWillAppear, it shows the UIImagePicker again. I think that it works.

您可以尝试正常关闭UIImagePicker,当Pre-viwer视图控制器激活viewWillDesapear时,您向前一个viewController“说”,当它在viewWillAppear时,它再次显示UIImagePicker。我认为它有效。

#3


1  

I had a similar problem in an app. I ended up presenting the image picker for the camera in a popover controller rather than modally for iPad. I'm not sure if this will work for your app but that's a different approach. I had no problems doing it this way and liked it much better.

我在应用程序中遇到了类似的问题。我最终在弹出控制器中呈现了相机的图像选择器,而不是模仿iPad。我不确定这是否适用于您的应用,但这是一种不同的方法。我这样做没有问题,并且更喜欢它。

#1


6  

On iPad when you are using sources different than camera feed, you are presenting UIImagePickerController in a popover and you can use it as long as you wish. But when you decide to pick up the source UIImagePickerControllerSourceTypeCamera the picker window is presenting full screen and you have two cases:

在iPad上使用不同于相机源的源时,您将在弹出窗口中呈现UIImagePickerController,您可以根据需要使用它。但是当你决定拿起源UIImagePickerControllerSourceTypeCamera时,选择器窗口呈现全屏,你有两种情况:

  1. If you use your custom controls (showsCameraControls = NO) you can take as much pictures as you want with the same controller.
  2. 如果您使用自定义控件(showsCameraControls = NO),您可以使用相同的控制器拍摄所需的照片。
  3. If you use default controls (showsCameraControls = YES), after taking ONE picture you MUST dissmiss the controller because it is unusable again and I guess this is your case. You are putting the next controller on the stack after taking the photo, after that you are trying to go back to your picker controller but it is unusable any more and you can see the black screen.
  4. 如果您使用默认控件(showsCameraControls = YES),在拍摄一张照片后,您必须关闭控制器,因为它再次无法使用,我猜这是您的情况。你拍摄照片后将下一个控制器放在堆叠上,之后你试图回到拾取器控制器,但它不再可用,你可以看到黑屏。

Apple docs for imagePickerController:didFinishPickingMediaWithInfo: :

imagePickerController的Apple文档:didFinishPickingMediaWithInfo ::

If you set the image picker’s showsCameraControls property to NO and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface. However, if you set that property to YES, your delegate must dismiss the image picker interface after the user takes one picture or cancels the operation.

如果将图像选择器的showsCameraControls属性设置为NO并提供自己的自定义控件,则可以在取消图像选择器界面之前拍摄多张图片。但是,如果将该属性设置为YES,则在用户拍摄一张照片或取消操作后,您的代理人必须关闭图像选择器界面。

If you want to take another picture in this case you have to go back to your base controller and create the UIImagePickerController instance one more.

如果您想在这种情况下拍摄另一张照片,则必须返回基本控制器并再创建一个UIImagePickerController实例。

I hope this will help.

我希望这将有所帮助。

Edit: The easiest way IMO to rebuild your view controllers stack is to dismiss the picker after taking a photo without animation and after that show the next controller with animation. It will give the user feeling, that the next controller is displayed just after the picker controller without any "flashing".

编辑:IMO重建视图控制器堆栈的最简单方法是在拍摄没有动画的照片后关闭选择器,之后显示下一个带动画的控制器。它会让用户感觉,下一个控制器就会在拾取器控制器之后显示而没有任何“闪烁”。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:NO completion:^{
        [self presentViewController:<newController> animated:YES completion:nil];
    }];
}

#2


1  

You can try dismiss normally the UIImagePicker, and when the Pre-viwer View Controller activate viewWillDesapear, you "say" to the previous viewController that when it viewWillAppear, it shows the UIImagePicker again. I think that it works.

您可以尝试正常关闭UIImagePicker,当Pre-viwer视图控制器激活viewWillDesapear时,您向前一个viewController“说”,当它在viewWillAppear时,它再次显示UIImagePicker。我认为它有效。

#3


1  

I had a similar problem in an app. I ended up presenting the image picker for the camera in a popover controller rather than modally for iPad. I'm not sure if this will work for your app but that's a different approach. I had no problems doing it this way and liked it much better.

我在应用程序中遇到了类似的问题。我最终在弹出控制器中呈现了相机的图像选择器,而不是模仿iPad。我不确定这是否适用于您的应用,但这是一种不同的方法。我这样做没有问题,并且更喜欢它。