【问题标题】:How to disable video capture in UIImagePickerController如何在 UIImagePickerController 中禁用视频捕获
【发布时间】:2011-07-06 17:46:12
【问题描述】:

我正在开发一个允许图像捕获但不允许视频捕获的应用程序,但我不知道如何从 UIImagePickerView 中删除照片/视频切换。这是我正在使用的代码,取自 Apple 的文档:

UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];

// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;

cameraUI.delegate = self;

[self presentModalViewController:cameraUI animated:YES];

我想保留除照片/视频开关之外的所有相机控件。谢谢!

【问题讨论】:

    标签: iphone objective-c ios camera


    【解决方案1】:

    或者删除这一行:

    cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
    

    cameraUI.mediaTypes 的默认值为“kUTTypeImage”。请参阅documentation

    【讨论】:

    • 别忘了#import <MobileCoreServices/UTCoreTypes.h>
    • 这确实是应该接受的答案。
    • 但是 kUTTypeImage 现在不可用了
    • @Gank 使用 kUTTypeImage 你需要这个:picker.mediaTypes = [kUTTypeImage as String]。您还必须导入MobileCoreServices。从这里回答:stackoverflow.com/a/32407457/144088
    • 最佳答案......谢谢我被困了大约 3 个小时,这只是一行代码......上帝保佑你
    【解决方案2】:

    您只需将 UIImagePickerController 的 mediaType 属性设置为仅包含图像,您使用的那个用于分配所有可用的媒体类型..如果您不确定是什么类型,您可以阅读它here您是否可以随时将它们输出到控制台,然后使用适当的数组设置该数组(仅允许图片)

    【讨论】:

    • 啊,好的。我通读了文档,就像你说的那样,我将 mediaType 设置为此似乎可行: cameraUI.mediaTypes = [[[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil] autorelease];
    • 别忘了#import <MobileCoreServices/UTCoreTypes.h>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多