質問編集履歴

3

boundsの値を追記しました。

2018/09/07 08:10

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -136,49 +136,49 @@
136
136
 
137
137
  // ①のときの各Viewの座標
138
138
 
139
- self.view.frame.origin.x 0.0
139
+ self.view.frame (0.0, 0.0, 1920.0, 1080.0)
140
140
 
141
- self.view.frame.origin.y 0.0
141
+ self.view.bounds (0.0, 0.0, 1920.0, 1080.0)
142
142
 
143
- self.view.layer.frame.origin.x 0.0
143
+ self.view.layer.frame (0.0, 0.0, 1920.0, 1080.0)
144
144
 
145
- self.view.layer.frame.origin.y 0.0
145
+ self.view.layer.bounds (0.0, 0.0, 1920.0, 1080.0)
146
146
 
147
- self.baseView.frame.origin.x 0.0
147
+ self.baseView.frame (0.0, 0.0, 1920.0, 1080.0)
148
148
 
149
- self.baseView.frame.origin.y 0.0
149
+ self.baseView.bounds (0.0, 0.0, 1920.0, 1080.0)
150
150
 
151
- self.ContainerView1.frame.origin.x 0.0
151
+ self.ContainerView1.frame (0.0, 0.0, 500.0, 1080.0)
152
152
 
153
- self.ContainerView1.frame.origin.y 0.0
153
+ self.ContainerView1.bounds (0.0, 0.0, 500.0, 1080.0)
154
154
 
155
- self.ContainerView2.frame.origin.x 500.0
155
+ self.ContainerView2.frame (500.0, 0.0, 1000.0, 1080.0)
156
156
 
157
- self.ContainerView2.frame.origin.y 0.0
157
+ self.ContainerView2.bounds (0.0, 0.0, 1000.0, 1080.0)
158
158
 
159
159
 
160
160
 
161
161
  // ②のときの各Viewの座標
162
162
 
163
- self.view.frame.origin.x -265.0
163
+ self.view.frame (-265.0, -162.0, 1920.0, 1080.0)
164
164
 
165
- self.view.frame.origin.y -162.0
165
+ self.view.bounds (0.0, 0.0, 1920.0, 1080.0)
166
166
 
167
- self.view.layer.frame.origin.x -265.0
167
+ self.view.layer.frame (-265.0, -162.0, 1920.0, 1080.0)
168
168
 
169
- self.view.layer.frame.origin.y -162.0
169
+ self.view.layer.bounds (0.0, 0.0, 1920.0, 1080.0)
170
170
 
171
- self.baseView.frame.origin.x 0.0
171
+ self.baseView.frame (0.0, 0.0, 1920.0, 1080.0)
172
172
 
173
- self.baseView.frame.origin.y 0.0
173
+ self.baseView.bounds (0.0, 0.0, 1920.0, 1080.0)
174
174
 
175
- self.ContainerView1.frame.origin.x 0.0
175
+ self.ContainerView1.frame (0.0, 0.0, 500.0, 1080.0)
176
176
 
177
- self.ContainerView1.frame.origin.y 0.0
177
+ self.ContainerView1.bounds (0.0, 0.0, 500.0, 1080.0)
178
178
 
179
- self.ContainerView2.frame.origin.x 500.0
179
+ self.ContainerView2.frame (500.0, 0.0, 1000.0, 1080.0)
180
180
 
181
- self.ContainerView2.frame.origin.y 0.0
181
+ self.ContainerView2.bounds (0.0, 0.0, 1000.0, 1080.0)
182
182
 
183
183
  ```
184
184
 

2

ソースと複数回遷移を実行した場合の座標位置を追加しました。

2018/09/07 08:10

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -14,19 +14,97 @@
14
14
 
15
15
  self.view以外に、画面AにあるUIViewを調べましたが、正しい位置の座標が返ってきています。
16
16
 
17
- ちなみに、画面Aは以下の構造になっています。
17
+ ちなみに、画面AはUIViewControllerで、ソースは以下のとおりです。
18
18
 
19
19
 
20
20
 
21
21
  ```
22
22
 
23
- ViewController
23
+ class ViewController: UIViewController {
24
24
 
25
- View(view.layer.insertSublayerにAVPlayerLayer)
25
+ var baseView: UIView = UIView()!
26
26
 
27
-  └ContainerView1
27
+ var containerView1: UIView! = UIView()!
28
28
 
29
-  └ContainerView2
29
+ var containerView2: UIView! = UIView()!
30
+
31
+
32
+
33
+ override func viewDidLoad() {
34
+
35
+ super.viewDidLoad()
36
+
37
+
38
+
39
+ self.view.translatesAutoresizingMaskIntoConstraints = false
40
+
41
+ self.baseView.translatesAutoresizingMaskIntoConstraints = false
42
+
43
+ self.containerView1.translatesAutoresizingMaskIntoConstraints = false
44
+
45
+ self.containerView2.translatesAutoresizingMaskIntoConstraints = false
46
+
47
+
48
+
49
+ self.view.addSubview(self.bgView)
50
+
51
+ self.bgView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
52
+
53
+ self.bgView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
54
+
55
+ self.bgView.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true
56
+
57
+ self.bgView.heightAnchor.constraint(equalTo: self.view.heightAnchor).isActive = true
58
+
59
+
60
+
61
+ self.baseView.addSubview(self.containerView1)
62
+
63
+ self.containerView1.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
64
+
65
+ self.containerView1.leftAnchor.constraint(equalTo: self.baseView.leftAnchor).isActive = true
66
+
67
+ self.containerView1.widthAnchor.constraint(equalToConstant: 500.0).isActive = true
68
+
69
+ self.containerView1.heightAnchor.constraint(equalTo: self.baseView.heightAnchor).isActive = true
70
+
71
+
72
+
73
+ self.baseView.addSubview(self.containerView2)
74
+
75
+ self.containerView2.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
76
+
77
+ self.containerView2.leftAnchor.constraint(equalTo: self.baseView.leftAnchor, constant: 500.0).isActive = true
78
+
79
+ self.containerView2.widthAnchor.constraint(equalToConstant: 1000.0).isActive = true
80
+
81
+ self.containerView2.heightAnchor.constraint(equalTo: self.baseView.heightAnchor).isActive = true
82
+
83
+
84
+
85
+ let asset = AVAsset(url: URL(string: "http://xxxxxxx.m3u8")
86
+
87
+ let playerItem = AVPlayerItem(asset: asset)
88
+
89
+ let player = AVPlayer(playerItem: playerItem)
90
+
91
+ player.play()
92
+
93
+
94
+
95
+ let movieLayer = AVPlayerLayer(player: player)
96
+
97
+ moviewLayer.frame = view.bounes
98
+
99
+ moviewLayer.videoGravity = .resizeAspectFill
100
+
101
+ movieLayer.zPosition = -1
102
+
103
+ view.layer.insertSublayer(self.movieLayer, at: 0)
104
+
105
+ }
106
+
107
+ }
30
108
 
31
109
  ```
32
110
 
@@ -44,6 +122,68 @@
44
122
 
45
123
 
46
124
 
125
+ ##追記
126
+
127
+ 画面A⇢画面B⇢A①⇢B⇢A②
128
+
129
+ のように画面遷移を行ったとき、①のタイミングと②のタイミングで座標の値が異なることがわかりました。
130
+
131
+ ②以降、B⇢Aと何回遷移を繰り返しても②と同じ座標が返ってきます。
132
+
133
+
134
+
135
+ ```
136
+
137
+ // ①のときの各Viewの座標
138
+
139
+ self.view.frame.origin.x 0.0
140
+
141
+ self.view.frame.origin.y 0.0
142
+
143
+ self.view.layer.frame.origin.x 0.0
144
+
145
+ self.view.layer.frame.origin.y 0.0
146
+
147
+ self.baseView.frame.origin.x 0.0
148
+
149
+ self.baseView.frame.origin.y 0.0
150
+
151
+ self.ContainerView1.frame.origin.x 0.0
152
+
153
+ self.ContainerView1.frame.origin.y 0.0
154
+
155
+ self.ContainerView2.frame.origin.x 500.0
156
+
157
+ self.ContainerView2.frame.origin.y 0.0
158
+
159
+
160
+
161
+ // ②のときの各Viewの座標
162
+
163
+ self.view.frame.origin.x -265.0
164
+
165
+ self.view.frame.origin.y -162.0
166
+
167
+ self.view.layer.frame.origin.x -265.0
168
+
169
+ self.view.layer.frame.origin.y -162.0
170
+
171
+ self.baseView.frame.origin.x 0.0
172
+
173
+ self.baseView.frame.origin.y 0.0
174
+
175
+ self.ContainerView1.frame.origin.x 0.0
176
+
177
+ self.ContainerView1.frame.origin.y 0.0
178
+
179
+ self.ContainerView2.frame.origin.x 500.0
180
+
181
+ self.ContainerView2.frame.origin.y 0.0
182
+
183
+ ```
184
+
185
+
186
+
47
187
  なぜこのようなことが起こってしまうのか、どう解決策を探したら良いのか検討もつきません。
48
188
 
49
189
  〜の設定が悪いのではないか、〜がおかしいのではないか、など、何かアタリがつく方いましたら教えてください。

1

正しい位置のスクリーンショット、self.view以外の座標位置を更新しました。

2018/09/07 08:04

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,35 @@
12
12
 
13
13
 
14
14
 
15
+ self.view以外に、画面AにあるUIViewを調べましたが、正しい位置の座標が返ってきています。
16
+
17
+ ちなみに、画面Aは以下の構造になっています。
18
+
19
+
20
+
21
+ ```
22
+
23
+ ViewController
24
+
25
+ └View(view.layer.insertSublayerにAVPlayerLayer)
26
+
27
+  └ContainerView1
28
+
29
+  └ContainerView2
30
+
31
+ ```
32
+
33
+
34
+
35
+ **正しい位置のスクリーンショット**
36
+
37
+ ![正しい状態のスクリーンショット](1d62efc998f8960ab4b1851d1c749936.png)
38
+
39
+
40
+
41
+ **ずれた位置のスクリーンショット**
42
+
15
- ![スクリーンショット](8df92fb26b524a3e352a04aa629b5b34.png)
43
+ ![ずれたスクリーンショット](8df92fb26b524a3e352a04aa629b5b34.png)
16
44
 
17
45
 
18
46