xcodeでAVPlayerViewControllerを使用し、iPhone上で動画の再生は出来るのですが、以下の画像のように、動画をピンチジェスチャーで拡大して再生することは可能でしょうか?
swift
1func pinchAction(sender: UIPinchGestureRecognizer) { 2 // imageViewを拡大縮小する 3 // ピンチ中の拡大率は0.3〜2.5倍、指を離した時の拡大率は0.5〜2.0倍とする 4 switch sender.state { 5 case .began, .changed: 6 // senderのscaleは、指を動かしていない状態が1.0となる 7 // 現在の拡大率に、(scaleから1を引いたもの) / 10(補正率)を加算する 8 currentScale = currentScale + (sender.scale - 1) / 10 9 // 拡大率が基準から外れる場合は、補正する 10 if currentScale < 0.3 { 11 currentScale = 0.3 12 } else if currentScale > 2.5 { 13 currentScale = 2.5 14 } 15 // 計算後の拡大率で、imageViewを拡大縮小する 16 imageView.transform = CGAffineTransform(scaleX: currentScale, y: currentScale) 17 default: 18 // ピンチ中と同様だが、拡大率の範囲が異なる 19 if currentScale < 0.5 { 20 currentScale = 0.5 21 } else if currentScale > 2.0 { 22 currentScale = 2.0 23 } 24 25 // 拡大率が基準から外れている場合、指を離したときにアニメーションで拡大率を補正する 26 // 例えば指を離す前に拡大率が0.3だった場合、0.2秒かけて拡大率が0.5に変化する 27 UIView.animate(withDuration: 0.2, animations: { 28 self.imageView.transform = CGAffineTransform(scaleX: self.currentScale, y: self.currentScale) 29 }, completion: nil) 30 31 } 32}
以上のコードでピンチジェスチャーで画像の拡大はできたのですが、同様に動画でもピンチジェスチャーで拡大できないかと思ったのですが、AVPlayerViewControllerで表示している動画には適用できなかったので、ご教授願いたいです。
回答2件
あなたの回答
tips
プレビュー