DEV Community

Xiong Yang
Xiong Yang

Posted on

When two videos are displayed on the phone screen their zoom and drag, they cannot exceed their respective size limits

If two videos are to be played simultaneously on the iPhone screen, and both videos have the function of zooming and dragging. Sometimes it is easy for the two videos to be zoomed in and dragged beyond their own size limits. This requires programmers to set them up so that the two videos do not interfere with each other and perform related actions in their respective areas.
The specific approach is as follows:

  1. Video A and Video B each need to load AVPlayer through a playerView to play the video, and the playerView here is the key factor for gesture zooming and dragging. The gesture is implemented on this playerView, and AVPlayer itself does not have the function of zooming and dragging;
  2. Add a parentView to load the playerView based on the view in 1. The playerView zooms and drags in the parentView, and all operations are fine. The key point is that the parentView should set clipsToBounds to true, and cut out all the content that exceeds the parentView range when zooming and dragging. This key is the most effective solution to solve the problem of the two videos exceeding the size limit when zooming and dragging.
self.parentView.clipsToBounds = true
Enter fullscreen mode Exit fullscreen mode

Top comments (0)