我正在尝试使用我的第一个iOS应用程序,而且我在获取刚刚拍摄的照片时遇到了一些问题。
以下是我的方法:
- (void)viewDidLoad
{
[super viewDidLoad];
//add imagePicker
_imgPicker = [[UIImagePickerController alloc] init];
_imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imgPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
_imgPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
_imgPicker.showsCameraControls = NO;
_imgPicker.navigationBarHidden = YES;
_imgPicker.toolbarHidden = YES;
_imgPicker.wantsFullScreenLayout = NO;
//add overlay on imagePicker
_imageSilhouette.image = [UIImage imageNamed:_pose.image];
_imgPicker.cameraOverlayView = _imageSilhouette;
[_vImagePreview addSubview:_imgPicker.view];
}
当我点击一个按钮时,我有一个计时器,10秒后,我拍照:
- (void)decreaseTimerCount
{
_lblTimer.text = [NSString stringWithFormat:@"%d", --_timerCount];
if(_timerCount==0)
{
[self takePicture];
}
}
-(void) takePicture{
[_timer invalidate];
[_imgPicker takePicture];
}
正如我在Apple文档中看到的,我添加了代理:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage * img = [info objectForKey:UIImagePickerControllerOriginalImage];
_imageSilhouette.image = img;
_imgPicker.cameraOverlayView = _imageSilhouette;
//[picker dismissModalViewControllerAnimated:YES];
}
但我真的不明白我是否必须在某处声明imagePickerController ..
我不明白,如果img确实包含我刚刚拍摄的照片吗?
我可以请一些帮助吗?
答案 0 :(得分:2)
在设置图像选择器的代码中,您需要添加以下内容:
_imgPicker.delegate = self;
此外,在您正在制作选择器的文件的.h
文件中,您需要在<>
之间添加代码
@interface SomeClass:NSObject <UIImagePickerControllerDelegate>
您可以选择在(.m)文件中添加(更好)选项,而不是在.h文件中添加协议。这样做可以避免告诉全世界您的班级使用图像选择器:
@interface SomeClass () <UIImagePickerControllerDelegate>
@end
在相应的@implementation
行之前添加此内容。