質問編集履歴

2

Swift4の記事を参考にコードを変更しました。

2019/03/28 07:19

投稿

shsw228
shsw228

スコア20

test CHANGED
File without changes
test CHANGED
@@ -119,3 +119,107 @@
119
119
 
120
120
 
121
121
  です。どう書くべきでしょうか…
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+ 追記
130
+
131
+ moviePlayerを
132
+
133
+ ```swift
134
+
135
+ func moviePlayer(url:String){
136
+
137
+
138
+
139
+ // 生成
140
+
141
+ let player = AVPlayer(url: URL(string: url)!)
142
+
143
+
144
+
145
+ // レイヤーの追加
146
+
147
+ let screenView = UIView()
148
+
149
+ screenView.frame = self.view.bounds
150
+
151
+ screenView.backgroundColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0)
152
+
153
+
154
+
155
+ let playerLayer = AVPlayerLayer(player: player)
156
+
157
+ playerLayer.frame = self.view.bounds
158
+
159
+ playerLayer.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor
160
+
161
+
162
+
163
+
164
+
165
+ let tapGesture:UITapGestureRecognizer = UITapGestureRecognizer(
166
+
167
+ target: self,
168
+
169
+ action: #selector(self.tapped(_:)))
170
+
171
+ tapGesture.delegate = self
172
+
173
+
174
+
175
+ screenView.addGestureRecognizer(tapGesture)
176
+
177
+ self.view.layer.addSublayer(playerLayer)
178
+
179
+ self.view.addSubview(screenView)
180
+
181
+ player.play()
182
+
183
+ if isTapped == true{
184
+
185
+ screenView.isHidden = true
186
+
187
+ print(isTapped)
188
+
189
+ isTapped = false
190
+
191
+ }
192
+
193
+
194
+
195
+ }
196
+
197
+
198
+
199
+ ```
200
+
201
+ に変更し
202
+
203
+ ```swift
204
+
205
+ @objc func tapped(_ sender:UITapGestureRecognizer){
206
+
207
+ if sender.state == .ended{
208
+
209
+ isTapped = true
210
+
211
+ print(isTapped)
212
+
213
+ }
214
+
215
+
216
+
217
+ }
218
+
219
+ ```
220
+
221
+ と、isTappedという名前のタップ状態を取る関数をViewController内に追加しました。
222
+
223
+ moviePlayer内でif isTapped...の文を書かずにタップだけ拾えているかprint文で見た所拾えていましたが上のコードではタップしても一度も反応しません…
224
+
225
+ if文は一度しか判定をしないということなのでしょうか…?

1

コード修正

2019/03/28 07:19

投稿

shsw228
shsw228

スコア20

test CHANGED
File without changes
test CHANGED
@@ -86,8 +86,6 @@
86
86
 
87
87
  playerLayer.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor
88
88
 
89
- screenView.addGestureRecognizer(tapGestureRecognizer)
90
-
91
89
 
92
90
 
93
91
  self.view.layer.addSublayer(playerLayer)