回答編集履歴
3
別の回答を追記
test
CHANGED
@@ -81,3 +81,77 @@
|
|
81
81
|
}
|
82
82
|
|
83
83
|
```
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
----
|
88
|
+
|
89
|
+
更に追記:
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
以下にもっと簡単な方法が載っていました。
|
94
|
+
|
95
|
+
AVPlayerViewController full screen rotation behavior in portrait only app
|
96
|
+
|
97
|
+
[https://stackoverflow.com/questions/50977823/avplayerviewcontroller-full-screen-rotation-behavior-in-portrait-only-app/51474721#51474721](https://stackoverflow.com/questions/50977823/avplayerviewcontroller-full-screen-rotation-behavior-in-portrait-only-app/51474721#51474721)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
手元でもうまく動作することを確認済み:
|
102
|
+
|
103
|
+
```swift:
|
104
|
+
|
105
|
+
import UIKit
|
106
|
+
|
107
|
+
import AVKit
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
class ViewController: UIViewController {
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
override func viewDidLoad() {
|
116
|
+
|
117
|
+
super.viewDidLoad()
|
118
|
+
|
119
|
+
// Do any additional setup after loading the view, typically from a nib.
|
120
|
+
|
121
|
+
title = "あああ"
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
let url = Bundle.main.url(forResource: "test", withExtension: "mp4")!
|
126
|
+
|
127
|
+
let player = AVPlayer(url: url)
|
128
|
+
|
129
|
+
let playerViewController = AVPlayerViewController()
|
130
|
+
|
131
|
+
playerViewController.player = player
|
132
|
+
|
133
|
+
addChild(playerViewController)
|
134
|
+
|
135
|
+
playerViewController.view.frame = CGRect(x: 0, y: 50, width: 200, height: 200)
|
136
|
+
|
137
|
+
view.addSubview(playerViewController.view)
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
override func viewWillAppear(_ animated: Bool) {
|
144
|
+
|
145
|
+
super.viewWillAppear(animated)
|
146
|
+
|
147
|
+
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
|
148
|
+
|
149
|
+
appDelegate.window?.rootViewController?.view.frame = UIScreen.main.bounds
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
```
|
2
回避方法の提案
test
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
-
SingleViewプロジェクトでナビゲーションバーを付加、
|
2
|
-
|
3
|
-
|
1
|
+
調査していたらクローズしてしまいましたが、一応力技で回避出来たので載せておきます。
|
4
|
-
|
5
|
-
以下のようなコードで実行し、
|
6
2
|
|
7
3
|
|
8
4
|
|
5
|
+
考え方自体はシンプルなのですが、
|
6
|
+
|
7
|
+
動画の最大化を解除したタイミングで、自分自身のビューコントローラーのframeを調整するというものです。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
最大化を解除はAVPlayerViewControllerのvideoBoundsを監視し、ウィンドウのバウンズと違うときを検出すれば良さそうでした。
|
12
|
+
|
13
|
+
|
14
|
+
|
9
|
-
```swift
|
15
|
+
```swift
|
10
16
|
|
11
17
|
import UIKit
|
12
18
|
|
@@ -15,6 +21,10 @@
|
|
15
21
|
|
16
22
|
|
17
23
|
class ViewController: UIViewController {
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
let playerViewController = AVPlayerViewController()
|
18
28
|
|
19
29
|
|
20
30
|
|
@@ -32,32 +42,42 @@
|
|
32
42
|
|
33
43
|
let player = AVPlayer(url: url)
|
34
44
|
|
35
|
-
|
45
|
+
|
36
46
|
|
37
|
-
|
47
|
+
playerViewController.player = player
|
38
48
|
|
39
|
-
addChild(
|
49
|
+
addChild(playerViewController)
|
40
50
|
|
41
|
-
|
51
|
+
playerViewController.view.frame = CGRect(x: 0, y: 50, width: 200, height: 200)
|
42
52
|
|
53
|
+
playerViewController.addObserver(self, forKeyPath: "videoBounds", options: [], context: nil)
|
54
|
+
|
55
|
+
|
56
|
+
|
43
|
-
view.addSubview(
|
57
|
+
view.addSubview(playerViewController.view)
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
64
|
+
|
65
|
+
if keyPath == "videoBounds" {
|
66
|
+
|
67
|
+
if playerViewController.videoBounds != UIScreen.main.bounds {
|
68
|
+
|
69
|
+
UIView.performWithoutAnimation {
|
70
|
+
|
71
|
+
self.navigationController?.view.frame = UIScreen.main.bounds
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
44
78
|
|
45
79
|
}
|
46
80
|
|
47
81
|
}
|
48
82
|
|
49
83
|
```
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
iPhone8(11.3)のシミュレーターで実行、
|
54
|
-
|
55
|
-
動画の最大化ボタンをタップ、画面を横向きにする、動画の最大化を解除する、
|
56
|
-
|
57
|
-
とやってみましたが、
|
58
|
-
|
59
|
-
~~おっしゃっているような症状は再現しませんでした。~~
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
最初から端末を横にして実行すると再現しました。失礼しました。
|
1
加筆
test
CHANGED
@@ -56,8 +56,8 @@
|
|
56
56
|
|
57
57
|
とやってみましたが、
|
58
58
|
|
59
|
-
おっしゃっているような症状は再現しませんでした。
|
59
|
+
~~おっしゃっているような症状は再現しませんでした。~~
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
-
|
63
|
+
最初から端末を横にして実行すると再現しました。失礼しました。
|