使用照片和摄像机?

时间:2015-11-20 09:21:38

标签: ios objective-c iphone camera uiimagepickercontroller

我想用iphone相机来拍摄照片或视频。

我知道如何打开JUST Photo Camera和JUST Video Camera,但我不知道如何在同一时间启动两者。

我可以使用UIImagePickerController在同一时间打开两者,还是需要创建自定义视图?

以下是专门用于相机和摄像机的代码

-(void)photoCameraButtonAction{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

-(void)videoCameraButtonAction{

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
        NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF contains %@)", @"movie"]];

        imagePicker.mediaTypes = videoMediaTypesOnly;
        imagePicker.videoQuality = UIImagePickerControllerQualityTypeMedium;
        imagePicker.videoMaximumDuration = 180;

        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

谢谢!

1 个答案:

答案 0 :(得分:0)

你可以这样做

        let picker = UIImagePickerController()
        picker.delegate = self
        picker.sourceType = .camera
        picker.mediaTypes = [kUTTypeMovie as String,kUTTypeImage as String]
        self.present(picker, animated: true, completion: nil)