UIImagePickerController 在 iPad 中崩溃

发布于 2024-10-17 20:54:58 字数 431 浏览 2 评论 0原文

-(IBAction)selectPressed:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

我正在 iPad 和 iPhone 模拟器上测试此代码。在 iPhone 模拟器中(以及在真实的 iPhone 上)没问题 - 会出现图库。但在iPad模拟器上(我没有设备),它崩溃了。有什么想法吗?

-(IBAction)selectPressed:(id)sender
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

I am testing this code on iPad and iPhone simulators. In the iPhone simulator (and on real iPhones too) it's ok - gallery appears. But on the iPad simulator (I don't have a device), it crashes. Any ideas why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

源来凯始玺欢你 2024-10-24 20:54:58

请阅读设备日志中的异常消息:

在 iPad 上,UIImagePickerController 必须通过 UIPopoverController 呈现

Please read the exception messages in the device log:

On iPad, UIImagePickerController must be presented via UIPopoverController

╰つ倒转 2024-10-24 20:54:58

麦克斯说:

在 iPad 上,UIImagePickerController 必须通过 UIPopoverController 呈现

现在看来,当 UIImagePickerController 的 sourceType 设置为 UIImagePickerControllerSourceTypeCamera 时,我们可以呈现 ModalViewController 和 UIImagePickerController。这一定是为了支持 iPad 2 的摄像头全屏视图。 Max 是正确的,当 sourceType 设置为其他任何值时,presentModalViewController 在 iPad 上崩溃。

Max said:

On iPad, UIImagePickerController must be presented via UIPopoverController

It now appears that we can presentModalViewController the UIImagePickerController when its sourceType is set to UIImagePickerControllerSourceTypeCamera. This must be to support the iPad 2's cameras in a full screen view. Max is correct that presentModalViewController crashes on iPads when sourceType is set to anything else.

鱼忆七猫命九 2024-10-24 20:54:58

在 iPad 上显示模态视图控制器时,该视图控制器还需要设置其 modalPresentationStyle 属性才能显示传入的视图。

以下是文档中可供您使用的选项:

typedef enum {
   UIModalPresentationFullScreen = 0,
   UIModalPresentationPageSheet,
   UIModalPresentationFormSheet,
   UIModalPresentationCurrentContext,
} UIModalPresentationStyle;

When displaying a modal view controller on the iPad, that view controller also needs it's modalPresentationStyle property to be set in order to display the incoming view.

Here are the options available to you from the documentation:

typedef enum {
   UIModalPresentationFullScreen = 0,
   UIModalPresentationPageSheet,
   UIModalPresentationFormSheet,
   UIModalPresentationCurrentContext,
} UIModalPresentationStyle;
两个我 2024-10-24 20:54:58

尝试将此代码用于 ipad 照片库,

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) 
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionAny 
                       animated:YES];

或者
http://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_(Xcode_4) ) 参考..

try using this code for ipad photolibrary,

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) 
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionAny 
                       animated:YES];

or
http://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_(Xcode_4) reference..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文