gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:05:01 35 4
gpt4 key购买 nike

我正在使用 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 模拟器上工作

最佳答案

从 iOS5 开始,您需要在弹出 View 而不是模态视图中显示选择器 Controller 。

来自苹果文档:在 iPad 上,使用弹出框呈现用户界面。仅当图像选择器 Controller 的 sourceType 属性设置为 UIImagePickerControllerSourceTypeCamera 时,这样做才有效。要使用 popover Controller ,请使用 UIPopoverController 类引用中“Presenting and Dismissing the Popover”中描述的方法。

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

这是在弹出 View 中显示 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];

关于ios - 使用 xcode 模拟器 IOS 5 测试 ipad 2 摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9074698/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com