質問編集履歴

1

文の修正

2018/12/20 06:54

投稿

moaikuntvs
moaikuntvs

スコア23

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