回答編集履歴
3
別の回答を追記
answer
CHANGED
@@ -39,4 +39,41 @@
|
|
39
39
|
}
|
40
40
|
}
|
41
41
|
}
|
42
|
+
```
|
43
|
+
|
44
|
+
----
|
45
|
+
更に追記:
|
46
|
+
|
47
|
+
以下にもっと簡単な方法が載っていました。
|
48
|
+
AVPlayerViewController full screen rotation behavior in portrait only app
|
49
|
+
[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)
|
50
|
+
|
51
|
+
手元でもうまく動作することを確認済み:
|
52
|
+
```swift:
|
53
|
+
import UIKit
|
54
|
+
import AVKit
|
55
|
+
|
56
|
+
class ViewController: UIViewController {
|
57
|
+
|
58
|
+
override func viewDidLoad() {
|
59
|
+
super.viewDidLoad()
|
60
|
+
// Do any additional setup after loading the view, typically from a nib.
|
61
|
+
title = "あああ"
|
62
|
+
|
63
|
+
let url = Bundle.main.url(forResource: "test", withExtension: "mp4")!
|
64
|
+
let player = AVPlayer(url: url)
|
65
|
+
let playerViewController = AVPlayerViewController()
|
66
|
+
playerViewController.player = player
|
67
|
+
addChild(playerViewController)
|
68
|
+
playerViewController.view.frame = CGRect(x: 0, y: 50, width: 200, height: 200)
|
69
|
+
view.addSubview(playerViewController.view)
|
70
|
+
}
|
71
|
+
|
72
|
+
override func viewWillAppear(_ animated: Bool) {
|
73
|
+
super.viewWillAppear(animated)
|
74
|
+
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
|
75
|
+
appDelegate.window?.rootViewController?.view.frame = UIScreen.main.bounds
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
42
79
|
```
|
2
回避方法の提案
answer
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
SingleViewプロジェクトでナビゲーションバーを付加、
|
2
|
-
|
1
|
+
調査していたらクローズしてしまいましたが、一応力技で回避出来たので載せておきます。
|
3
|
-
以下のようなコードで実行し、
|
4
2
|
|
3
|
+
考え方自体はシンプルなのですが、
|
4
|
+
動画の最大化を解除したタイミングで、自分自身のビューコントローラーのframeを調整するというものです。
|
5
|
+
|
6
|
+
最大化を解除はAVPlayerViewControllerのvideoBoundsを監視し、ウィンドウのバウンズと違うときを検出すれば良さそうでした。
|
7
|
+
|
5
|
-
```swift
|
8
|
+
```swift
|
6
9
|
import UIKit
|
7
10
|
import AVKit
|
8
11
|
|
9
12
|
class ViewController: UIViewController {
|
13
|
+
|
14
|
+
let playerViewController = AVPlayerViewController()
|
10
15
|
|
11
16
|
override func viewDidLoad() {
|
12
17
|
super.viewDidLoad()
|
@@ -15,18 +20,23 @@
|
|
15
20
|
|
16
21
|
let url = Bundle.main.url(forResource: "test", withExtension: "mp4")!
|
17
22
|
let player = AVPlayer(url: url)
|
23
|
+
|
24
|
+
playerViewController.player = player
|
18
|
-
|
25
|
+
addChild(playerViewController)
|
19
|
-
vc.player = player
|
20
|
-
addChild(vc)
|
21
|
-
|
26
|
+
playerViewController.view.frame = CGRect(x: 0, y: 50, width: 200, height: 200)
|
27
|
+
playerViewController.addObserver(self, forKeyPath: "videoBounds", options: [], context: nil)
|
28
|
+
|
22
|
-
view.addSubview(
|
29
|
+
view.addSubview(playerViewController.view)
|
23
30
|
}
|
31
|
+
|
32
|
+
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
33
|
+
if keyPath == "videoBounds" {
|
34
|
+
if playerViewController.videoBounds != UIScreen.main.bounds {
|
35
|
+
UIView.performWithoutAnimation {
|
36
|
+
self.navigationController?.view.frame = UIScreen.main.bounds
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
24
41
|
}
|
25
|
-
```
|
42
|
+
```
|
26
|
-
|
27
|
-
iPhone8(11.3)のシミュレーターで実行、
|
28
|
-
動画の最大化ボタンをタップ、画面を横向きにする、動画の最大化を解除する、
|
29
|
-
とやってみましたが、
|
30
|
-
~~おっしゃっているような症状は再現しませんでした。~~
|
31
|
-
|
32
|
-
最初から端末を横にして実行すると再現しました。失礼しました。
|
1
加筆
answer
CHANGED
@@ -27,6 +27,6 @@
|
|
27
27
|
iPhone8(11.3)のシミュレーターで実行、
|
28
28
|
動画の最大化ボタンをタップ、画面を横向きにする、動画の最大化を解除する、
|
29
29
|
とやってみましたが、
|
30
|
-
おっしゃっているような症状は再現しませんでした。
|
30
|
+
~~おっしゃっているような症状は再現しませんでした。~~
|
31
31
|
|
32
|
-
|
32
|
+
最初から端末を横にして実行すると再現しました。失礼しました。
|