HomeiOS Developmentios - Tips on how to implement easy pinch-to-zoom for AVPlayerLayer with...

ios – Tips on how to implement easy pinch-to-zoom for AVPlayerLayer with out interrupting video playback?


I am engaged on an iOS app utilizing Swift and want to add pinch-to-zoom assist for video playback utilizing AVPlayer. My aim is to let customers zoom in on the video utilizing pinch gestures, much like how pictures could be zoomed with UIImageView.

Right here’s what I would like to realize:

  • Zoom in/out with pinch gestures on a video participant
  • Keep playback throughout zoom (no pause or stutter)
  • Clean reset to authentic scale after pinch ends
  • Disguise UI controls whereas zooming, and restore them when zoom ends

Thus far, I’ve tried making use of transforms like this:

@objc func handlePinch(_ gesture: UIPinchGestureRecognizer) {
    swap gesture.state {
    case .modified:
        let scale = gesture.scale
        playerLayer.setAffineTransform(CGAffineTransform(scaleX: scale, y: scale))
    case .ended, .cancelled:
        UIView.animate(withDuration: 0.25) {
            self.playerLayer.setAffineTransform(.identification)
        }
    default:
        break
    }
}

This works to some extent, however feels glitchy — particularly when zooming again. I’m uncertain if remodeling AVPlayerLayer like that is finest apply, or if there’s a extra sturdy method (e.g., wrapping it in a view, utilizing CATransform3D, and so forth.).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments