【发布时间】:2012-06-08 19:00:10
【问题描述】:
我的朋友们,我用谷歌搜索了很多,但一无所获。我正在关注本教程:http://www.musicalgeometry.com/?p=821,我的目标是放置一个新按钮来拍照。但我不知道调用拍照相机方法。
【问题讨论】:
标签: iphone objective-c ios camera
我的朋友们,我用谷歌搜索了很多,但一无所获。我正在关注本教程:http://www.musicalgeometry.com/?p=821,我的目标是放置一个新按钮来拍照。但我不知道调用拍照相机方法。
【问题讨论】:
标签: iphone objective-c ios camera
最简单的方法是使用 UIImagePickerController 类。您可以以模态方式呈现此视图控制器,您将获得带有拍摄照片的委托回调。
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
else // The device doesn't have a camera, so use something like the photos album
[imagePicker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
[self presentViewControler:imagePicker animated:YES completion:nil];
要使用的委托方法是:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
如果您需要在不使用 UIImagePickerController 的情况下拍照,比如说您想要自己的自定义界面,则需要深入了解 AVFoundation,这是一个您可能还没有准备好的高级主题。
【讨论】:
您需要查看UIImagePickerController 类,该类可让您访问 iOS 设备的相机功能。
具体来说,您需要使用源类型UIImagePickerControllerSourceTypeCamera(首先通过isSourceTypeAvailable: 检查设备是否有摄像头),媒体类型为kUTTypeImage,通过presentViewController 显示摄像头控制器,然后您然后可以显示默认的相机控件,或者在用户按下自定义按钮时通过触发takePicture 方法来隐藏它们并拍照。
【讨论】: