Allow UIImagePickerController to edit video but no

2019-06-17 03:06发布

问题:

Uploading an image or video in Whatsapp, seems to use a UIImagePicker.

It's possible to edit video in that view, but images can't be edited. It seems that in the SDK, the allowsEditing property determines whether editing is allowed for both images and video.

How can I get the behavior like Whatsapp, where video can be edited but images cannot?

回答1:

I was able to achieve this functionality by listening for notifications from the picker. Sign-up in ViewDidLoad

  [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(imageCaptured:)
                                             name:@"_UIImagePickerControllerUserDidCaptureItem" object:nil]; 

Than determine when to allowing editing

   - (void) imageCaptured:(NSNotification *)notification
   {
       if (self.pickerController.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo) {
            self.pickerController.allowsEditing = YES;
         }
         else{
            self.pickerController.allowsEditing = NO; 
         {
   }


回答2:

To disallow image editing set allowsEditing = false.

To allow video editing, present the picked video in a UIVideoEditorController.

Or use a custom image / video picker that you can configure to your liking.