2013-03-28 92 views
1

只是为了确保我有所有的代码的权利,这是我的头文件:iOS模拟器能够模拟设备的摄像头吗?

#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 

然后这里是我的实现:

#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

建议,非常感谢!

+3

不,它没有,但错误甚至不是这样。尝试阅读并理解错误消息。 – 2013-03-28 21:56:12

回答

8

从苹果:

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

硬件仿真支持

iPhone模拟器不模拟加速度计或摄像头硬件。

此外,H2CO3是正确的,你有一个不同的问题和错误消息是相当清楚的:

快速谷歌搜索“在iPad上,必须的UIImagePickerController通过UIPopoverController呈现”指出我下面的链接。查看Zubair的回复。我认为你需要在iPad上运行时将UIImagePickerController呈现在弹出窗口中。

UIStatusBarStyleBlackTranslucent is not available on this device

+0

谢谢,我只是自己搜索了UIPopoverController,并找到了一个可行的解决方案。但是,是的,相机仍然是不行,所以感谢您提供该链接! – Taylor

+0

没有汗,祝你好运! – Aaron

0

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