首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS模拟器是否有能力模拟设备的摄像头?

iOS模拟器是否有能力模拟设备的摄像头?
EN

Stack Overflow用户
提问于 2013-03-29 05:53:41
回答 2查看 8.4K关注 0票数 1

为了确保所有代码都正确,下面是我的头文件:

代码语言:javascript
运行
复制
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate> {

    IBOutlet UIImageView *imageView;
    IBOutlet UIButton *choosePhoto;
    IBOutlet UIButton *takePhoto;

}

@property(nonatomic, retain) UIButton *choosePhoto;

@property(nonatomic, retain) UIButton *takePhoto;

@property(nonatomic, retain) UIImageView *imageView;

-(IBAction)getPhoto:(id)sender;
-(IBAction)takePhoto:(id)sender;

@end

下面是我的实现:

代码语言:javascript
运行
复制
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize imageView,choosePhoto,takePhoto;

- (void)viewDidLoad
{
    [super viewDidLoad];

}

-(IBAction)getPhoto:(id)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentViewController:picker animated:YES completion:nil];
}

-(IBAction)takePhoto:(id)sender {

    UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
    picker2.delegate = self;
    picker2.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker2 animated:YES completion:nil];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [picker dismissViewControllerAnimated:YES completion:nil];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}

@end

我的界面构建器中有两个UIButtons和一个UIIImageView。测试应用程序构建良好,没有任何问题,但当我按下选择照片或拍照按钮时,应用程序崩溃。这仅仅是因为模拟器在技术上没有相机或照片库可供选择吗?这是它给我的错误:UIStatusBarStyleBlackTranslucent在这个设备上不可用。

Cameratest[8290:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController

非常感谢您的建议!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-29 06:18:41

来自苹果:

http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/ios_development_workflow/25-Using_iOS_Simulator/ios_simulator_application.html

硬件模拟支持

iOS模拟器不模拟加速度计或相机硬件。

此外,H2CO3是对的,你有一个不同的问题,错误消息非常清楚:

‘在iPad上,UIIMagePickerController必须通过UIPopoverController呈现’

我在谷歌上快速搜索一下,找到了下面的链接。看看Zubair对此的回应。我认为当在iPad上运行时,你需要在弹出窗口中显示UIImagePickerController。

UIStatusBarStyleBlackTranslucent is not available on this device

票数 8
EN

Stack Overflow用户

发布于 2013-10-28 15:38:07

没有模拟器不支持模拟摄像头。对于相机,你必须在设备上运行应用程序

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15692838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档