teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

文の修正

2018/12/20 06:54

投稿

moaikuntvs
moaikuntvs

スコア23

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