使用 xcode 模拟器 IOS 5 测试 ipad 2 摄像头

发布于 2025-01-01 11:06:52 字数 997 浏览 2 评论 0原文

我正在使用 ipad 模拟器测试 ipad 相机应用程序 我使用下面的代码,更改源类型而不是相机。

  -(IBAction)useCamera:(id)sender{


    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){

    UIImagePickerController *imagePicker = 
    [[UIImagePickerController alloc] init];
    imagePicker.delegate =(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
    imagePicker.allowsEditing = NO;
    [self presentModalViewController:imagePicker animated:YES];

    [imagePicker release];
    newMedia = YES;

    }

当它在模拟器中运行时,

ios 5 模拟器中出现错误。

   Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'On iPad,     UIImagePickerController must be presented via UIPopoverController' 

但它可以在 4.3 模拟器上运行

I am testing ipad camera application with ipad simulator
I used below code, change the source type instead of camera.

  -(IBAction)useCamera:(id)sender{


    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){

    UIImagePickerController *imagePicker = 
    [[UIImagePickerController alloc] init];
    imagePicker.delegate =(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
    imagePicker.allowsEditing = NO;
    [self presentModalViewController:imagePicker animated:YES];

    [imagePicker release];
    newMedia = YES;

    }

}

When it run in the simulator error came up in ios 5 simulator .

   Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'On iPad,     UIImagePickerController must be presented via UIPopoverController' 

But its working on 4.3 simulator

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

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

发布评论

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

评论(1

滥情哥ㄟ 2025-01-08 11:06:52

从 iOS5 开始,您需要在弹出视图而不是模态视图中显示 pickercontroller。

来自苹果文档:在 iPad 上,使用弹出框呈现用户界面。仅当图像选择器控制器的 sourceType 属性设置为 UIImagePickerControllerSourceTypeCamera 时,这样做才有效。要使用弹出窗口控制器,请使用 UIPopoverController 类参考中的“呈现和关闭弹出窗口”中描述的方法。

http://developer.apple.com/ Library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

下面是一个展示弹出视图内的 UIImagePickerController:

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

Starting with iOS5 you need to show the pickercontroller in a popover view rather than a modal view.

From the apple documentation: On iPad, present the user interface using a popover. Doing so is valid only if the sourceType property of the image picker controller is set to UIImagePickerControllerSourceTypeCamera. To use a popover controller, use the methods described in “Presenting and Dismissing the Popover” in UIPopoverController Class Reference.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

Here is an example of presenting a UIImagePickerController inside a popover view:

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