[英]How to set allowsEditing for UIImagePickerController only for videos selected from photo library in iOS?
I'm using UIImagePickerController in my applicaiton. 我在我的应用程序中使用UIImagePickerController。 I'm showing the following alert in button action.
我在按钮操作中显示以下警报。
My code looks like the following in alertview delegate method: 我的代码在alertview委托方法中如下所示:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView.title isEqualToString:@"Choose"]) {
if (buttonIndex == 1) { //Camera
[self presentImagePickerControllerWithCamera:YES];
}
else if(buttonIndex == 2) { //Library
[self presentImagePickerControllerWithCamera:NO];
}
}
}
and the content of the method 'presentImagePickerControllerWithCamera' is: 方法“ presentImagePickerControllerWithCamera”的内容为:
- (void)presentImagePickerControllerWithCamera:(BOOL)isCamera {
CFStringRef mTypes[2] = { kUTTypeImage, kUTTypeMovie };
CFArrayRef mTypesArray = CFArrayCreate(CFAllocatorGetDefault(), (const void**)mTypes, 2, &kCFTypeArrayCallBacks);
imagePickerController.mediaTypes = (__bridge NSArray*)mTypesArray;
imagePickerController.videoMaximumDuration = 60.0f;
CFRelease(mTypesArray);
if (isCamera) { // Showing the camera (Both Camera and video)
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;
imagePickerController.allowsEditing = NO;
}
else { // Showing library (Both Pictures and videos)
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:imagePickerController animated:YES completion:nil];
}
Here i need to limit the video to 1 min when user is selecting video from library, so i wrote 在这里,当用户从库中选择视频时,我需要将视频限制为1分钟,所以我写了
imagePickerController.videoMaximumDuration = 60.0f;
and 和
imagePickerController.allowsEditing = YES;
it's working fine. 工作正常。 But When the user selects a picture from library i don't want editing(the square box on picture).
但是,当用户从库中选择图片时,我不想编辑(图片上的方框)。 Is there any way to achieve it?
有什么办法可以实现?
Any suggestions would be appreciated. 任何建议,将不胜感激。 Thanks in advance.
提前致谢。
This isn't possible with your current code. 您当前的代码无法执行此操作。
You've assigned both the media types together. 您已经将两种媒体类型一起分配了。 That will show you both image& video in to photo gallery.
这将向您显示图像和视频都进入相册。 Once
UIImagePickerController
will show you'll not have access to it, I mean you can't know what user will select (an image or a video) before delegate get call. 一旦
UIImagePickerController
将显示您将无权使用它,我的意思是您不知道在委托被调用之前用户将选择什么(图像或视频)。
So to achieve this with your case, you've to set each media type at once. 因此,要实现此目的,您必须立即设置每种媒体类型。 And based on that media type, have to set
allowsEditing
property. 并且基于该媒体类型,必须设置
allowsEditing
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.