zoom in AVPlayerViewController in iOS9

How do i enable pinch-to-zoom in AVPlayerViewController like the video player in the Phots app for example? I this a feature provided by AVKit in iOS9 or do i have to implement my own zoom with UIScrollView and a Gesture Recognizer?


Thanks.

I was able to use a swiping gesture to edit the zoom. I'm sure you could modify what I've done to get the effect you need. I added a Pan Gesture Recgonizer to my view and then in my VC I added an @IBAction. Inside that method i implemented the switch statement of the gesture recognizer. Under the .Changed I created a translation variable. I then made a do{}catch{} to lock/unlockForConfiguration() I made a new variable for the zoom change using the translation.y and multipled it by a negative and a huge number so the zoom wasn't insanely fast and swiping up zoomed in swiping down zoomed out. I then altered the device's zoom by setting the .videoZoomFactor.

@IBAction func panToZoom(gesture: UIPanGestureRecognizer) {

let device: AVCaptureDevice! = self.videoDeviceInput!.device

switch gesture.state{

case .Ended: fallthrough

case .Changed:

let translation = gesture.translationInView(self.view)

do{

try device.lockForConfiguration()

let zoomChange = -(translation.y / 3000)

device.videoZoomFactor = min(max(device.videoZoomFactor + zoomChange, 1), 10)

device.unlockForConfiguration()

}catch{

fatalError("you failed due to zoom error!")

}

default: break

}

}


If you add a pinch gesture recognizer to your view and then take the distance changed rather than the translation of the Y axis you could essentially enable a pinch-to-zoom feature. Hope this helps.

zoom in AVPlayerViewController in iOS9
 
 
Q