Range slider’s touch (box) of video trimmer “off”

i0S Swift Issue

Question or problem with Swift language programming:

I am using FDTake (the pod wont be too important for this question but still) to select videos from Photos which works fine. However, I would also like to be able to edit videos and limit their length to about 12 seconds. To do so I looked at the code of the pod and changed line 271 to self.imagePicker.allowsEditing = true which already causes the problem I haven’t been able to solve so far: The left slider’s touch (box) is “off”. Since that’s a rather vague description I uploaded a video and you can find it right here.

Unfortunately, I have absolutely no idea what engenders the problem and would really appreciate some help with this. I asked the creator of FDTake but apparently he thinks that Apple needs to fix this (as you’ll be able to see in one of the latest closed issues).

Can someone explain how I can fix this and what is causing it?

How to solve the problem:

Solution 1:

One possible Solution: Select the video and then trim the video using PryntTrimmerView

You can use PryntTrimmerView library for trimming the videos. I have implemented this library in a sample project. You can download the running sample project from my github repo Here

The load random video button loads a random video from device’s storage (photos). Therefore atleast one video file needs to be present

An Avplayer is being used for displaying the video

This is complete video

Complete video


Use the black handles to trim the video as desired

Trimming the Video

Trimming the video


Note: : Minimum Allowed distance between handles is specified in PryntTrimmerView.swift file using a private property.

/// The minimum duration allowed for the trimming. The handles won't pan further if the minimum duration is attained.
  public var minDuration: Double = 2

And this function uses this property along with video duration and frame to calculate minimum distance bw handles

private var minimumDistanceBetweenHandle: CGFloat {
    guard let asset = asset else { return 0 }
    let distance = CGFloat(minDuration) * assetPreview.contentView.frame.width / CGFloat(asset.duration.seconds)
    print("minimum distance: \(distance)")
    return distance
  }

Let me know if you encounter any problems or need more information

Thanks

Solution 2:

I’ve reproduced the issue using an UIImagePickerController directly.

Here is some code that you can call from your viewController:

 let picker = UIImagePickerController()
 picker.allowsEditing = true
 picker.mediaTypes = [String(kUTTypeMovie)]
 picker.videoMaximumDuration = 12.0

 present(picker, animated: true, completion: nil)

My guess is that there is a gesture conflict with some internal view only on the left side of the screen, once you’ve pulled the left handle somewhere in the middle, you can access it directly.

Also, this does not seem to be new: IOS 11 UIImagepicker for video how to move the slider to the bottom?

The best thing you can do is to file a radar to Apple.

In the meantime, you can use the library suggested by Awais Fayyaz as a workaround. (Disclaimer: I’m the author of the library, so I am biased of course).
Another option would be to use an UIVideoEditorController once the user has selected the video, that component does not have any issue on iOS 11.

Solution 3:

We’ve had the same problem here. It certainly has to do with gestures on the left side of the screen.

When you add additionalSafeAreaInsets to your UIImagePickerController it works much better.

This is what we tried:

 let imagePickerController = UIImagePickerController()
 imagePickerController.allowsEditing = true
 imagePickerController.mediaTypes = [kUTTypeMovie as String]
 imagePickerController.videoMaximumDuration = 12.0
 imagePickerController.additionalSafeAreaInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)

We ended up using the UIVideoEditorController.

Hope this helps!