- #pragma mark - 相机调用拍照
- - (void)didClickRightButton{
- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
- UIImagePickerController * cameraPicker = [[UIImagePickerController alloc] init];
- cameraPicker.delegate = self;
- cameraPicker.allowsEditing = YES;
- cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
- // 相机的调用为照相模式
- cameraPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
- // 设置为NO则隐藏了拍照按钮
- cameraPicker.showsCameraControls = YES;
- // 设置相机摄像头默认为前置
- cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
- // 设置相机闪光灯开关
- cameraPicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
- // 用来设置覆盖在你照相图像上,可以自定义位置或图片(类似美图秀秀加个小猫小狗小花修饰)
- //cameraPicker.cameraOverlayView
- // 用来修改拍照相框
- //cameraPicker.cameraViewTransform
- [self presentViewController:cameraPicker animated:YES completion:nil];
- [cameraPicker release];
- } else {
- NSLog(@"当前设备不支持相机调用");
- }
- }
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
- /*-------------------------------相机拍照--------------------------------------*/
- if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
- UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
- _imageView.image = image;
- [self dismissViewControllerAnimated:YES completion:^{
- }];
- } else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
- /**
- * UIImagePickerControllerEditedImage 取得的是被编辑过的图片,需要allowsEditing设置为YES
- * UIImagePickerControllerOriginalImage 取得的是相册中原始图片
- */
- UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
- _imageView.image = image;
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- /*-------------------------------相机录像--------------------------------------*/
- if (picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo) {
- // 获得视频路径
- NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
- // 存储视频(@selector里面的方法一定要是这种格式)
- UISaveVideoAtPathToSavedPhotosAlbum([url path], self, @selector(video:didFinishSavingWithError: contextInfo:), nil);
- [self dismissViewControllerAnimated:YES completion:nil];
- }else if(picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModePhoto){
- }
- }
- - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{
- NSLog(@"%s",__FUNCTION__);
- }
- #pragma mark - 相机调用拍视频
- - (void)didClickLeftButton{
- BOOL judge = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
- if (judge) {
- UIImagePickerController * cameraPicker = [[UIImagePickerController alloc] init];
- cameraPicker.delegate = self;
- cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
- // 视频录制的规定时间
- // cameraPicker.videoMaximumDuration = 10;
- // 引入 MobileCoreServices.framework 库, 设置viedo依托的.media
- // 这句话必须放在设置cameraCaptureMode前面,涉及到一个API执行顺序问题
- cameraPicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
- // 相机调用为录像模式
- cameraPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
- [self presentViewController:cameraPicker animated:YES completion:nil];
- } else {
- NSLog(@"当前设备不支持相机的调用");
- }
- }
- - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
- [self presentViewController:cameraPicker animated:YES completion:nil];
- NSLog(@"%s",__FUNCTION__);
- }
@细心的朋友可能会发现,明明设置里面是中文,调用的相机显示的标题仍然是英文,如何把如cancel->取消
这样就OK了