如何在UIImagePickerController中禁用视频捕获

dno*_*ott 17 iphone camera objective-c ios

我正在开发一个允许图像捕获但不是视频捕获的应用程序,但我无法弄清楚如何从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];
Run Code Online (Sandbox Code Playgroud)

除了照片/视频开关外,我想保留所有相机控制.谢谢!

小智 31

或删除此行:

cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
Run Code Online (Sandbox Code Playgroud)

cameraUI.mediaTypes的默认值是"kUTTypeImage".请参阅文档.


Dan*_*iel 16

您只需要将UIImagePickerController的mediaType属性设置为仅包含图像,您在那里使用的图像用于分配所有可用的媒体类型.您可以在此处阅读它,如果您不确定哪些类型可以始终输出他们控制台然后只用适当的一个设置该数组(只允许图片)

  • 喔好吧.我阅读了文档,就像你说的那样我将mediaType设置为这似乎有效:cameraUI.mediaTypes = [[[NSArray alloc] initWithObjects:(NSString*)kUTTypeImage,nil] autorelease]; (7认同)
  • 别忘了`#import <MobileCoreServices/UTCoreTypes.h>` (3认同)