简体   繁体   English

如何为仅从iOS中的图片库中选择的视频设置allowEditing for UIImagePickerController?

[英]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.

相关问题 iOS - 如何使用allowEditing在UIImagePickerController中自定义crop rect? - iOS - How to customize the crop rect in UIImagePickerController with allowsEditing on? 从照片库中选择视频时,文件大小仅适用于 iOS 13.2 上 Ionic 中的视频 - File size is 0 only for videos in Ionic on iOS 13.2 when selecting videos from Photo Library iOS7 UIImagePickerController允许编辑无法正常工作 - iOS7 UIImagePickerController allowsEditing not working correctly swift:如何在不使用UIImagePickerController的情况下从照片库加载照片? - swift: How to load photos from photo library without using UIImagePickerController? 如何使用 UIImagePickerController 从照片库中删除图像 - How to delete an image from photo library using UIImagePickerController 使用UIImagePickerController从照片库中访问相机 - Accessing camera from within the photo library with UIImagePickerController UIImagePickerController - 从照片库中挑选背景中的视频 - UIImagePickerController - picking video in background from photo library UIImagePickerController 和照片库访问 - UIImagePickerController and photo library access 如何使用 UIImagePickerController 设置拍摄照片的位置 - How to set the location for the captured photo by using UIImagePickerController 如何使用UIImagePickerController设置捕获的照片的位置? - How to set the location for the captured photo by using UIImagePickerController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM