将Video Recorder解除为新的ViewController

时间:2013-08-25 23:49:28

标签: iphone objective-c uiviewcontroller uiimagepickercontroller dismiss

在我的应用程序中,我允许用户选择是否要从库中选择照片,使用相机拍照,或使用相机录制视频。

使用相机选择或拍摄照片后,点击使用将关闭UIImagePickerController并将用户带到新的UIViewController。

我想在用户录制视频时也这样做。现在,如果用户点击“使用”按钮,它就会取消选择器。

如何检测选择器是否设置为录制视频?

以下是我的尝试:

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
 {

     if (picker.mediaTypes == [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera] && picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo)
     {
          // Push to new view controller
          // dismiss the picker
     }

 }

有可能这样做吗?我应该检查什么?

谢谢!

2 个答案:

答案 0 :(得分:0)

请参阅Apple的"Camera Programming Topics for iOS"。这里的建议是实现imagePickerController:didFinishPickingMediaWithInfo:而不是imagePickerController:didFinishPickingImage:editingInfo:(自iOS 3以来已弃用)。然后,可以检查信息词典的UIImagePickerControllerMediaType键的值,并与适当的类型进行比较。

例如(请注意,您需要添加MobileCoreServices框架,并导入其标头):

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *pickedMediaType = info[UIImagePickerControllerMediaType];
    NSString *movieType = (__bridge NSString *)kUTTypeMovie;
    NSString *imageType = (__bridge NSString *)kUTTypeImage;

    if ([pickedMediaType isEqualToString:movieType]) {
        NSLog(@"movie was picked");
    }
    else if ([pickedMediaType isEqualToString:imageType]) {
        NSLog(@"image was picked");
    }
    else {
        NSLog(@"something else was picked");
    }

    [self dismissViewControllerAnimated:YES completion:nil];
}

在您的应用程序中,您将使用适当的操作替换日志记录语句(从您的问题来看,听起来您已经有代码要推送到新的视图控制器,因此请相应地替换日志记录语句)。另请注意you generally shouldn't compare Objective-C objects with ==。在我比较字符串时,我使用isEqualToString:

答案 1 :(得分:0)

使用下面提到的代码来检测视频的录制,在解雇结束时它转到detailviewcontroller

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
[picker dismissModalViewControllerAnimated:YES];

NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];  

//not production code,  do not use hard coded string in real app
if ( [mediaType isEqualToString:@"public.image" ]) 
{                                                                                                        
    NSLog(@"Picked a photo");
}
//not production code,  do not use hard coded string in real app
else if ( [ mediaType isEqualToString:@"public.movie" ])
{
    NSLog(@"Picked a movie at URL %@",  [info objectForKey:UIImagePickerControllerMediaURL]);
    NSURL *url =  [info objectForKey:UIImagePickerControllerMediaURL];
    NSLog(@">>>>>>>>>>> Url %@", [url absoluteString]);
    RecordDetailiPhone *objDetail = [[RecordDetailiPhone alloc] initWithNibName:@"RecordDetailiPhone" bundle:nil];
    [objDetail saveVideoFileToDeractory:url];
    [self.navigationController pushViewController:objDetail animated:YES];
}
}