我使用以下代码来呈现UIImagePickerController。对于某些特定情况,我只想要视频。并使用以下代码。
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController.allowsEditing=NO;
imagePickerController.mediaTypes=[[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,nil];
[self presentViewController:imagePickerController animated:YES completion:nil];
但是它在桌面视图中显示了相机胶卷,我的照片流和视频。如果我打开任何文件夹,内容只是视频。我想要只有视频我怎样才能实现这一点。还有标题照片,我想改变它也toVideos。
答案 0 :(得分:7)
Swift 3更新:
let videoPicker = UIImagePickerController()
videoPicker.delegate = self
videoPicker.sourceType = .photoLibrary
videoPicker.mediaTypes = [kUTTypeMovie as String]
self.present(videoPicker, animated: true, completion: nil)
导入导入MobileCoreServices 并在顶部添加代理 UIImagePickerControllerDelegate 和 UINavigationControllerDelegate
呈现的模态将具有“照片”标题。 您可以这样更改:
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
viewController.navigationItem.title = "Choose Video"
}
答案 1 :(得分:2)
#import <MobileCoreServices/MobileCoreServices.h>
和
[controller setMediaTypes:@[(NSString *)kUTTypeMovie]];
答案 2 :(得分:0)
您无法一次性获取所有视频集(从相机胶卷,照片库),您需要导航到#34;相机胶卷&#34;,&#34;照片库&#34;选择所需的视频。
您可以选择以下任何枚举的源类型
typedef NS_ENUM(NSInteger, UIImagePickerControllerSourceType) {
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
};
并设置所需的媒体类型。