我想在执行手势时通过参数传递两个参数,滑动手势和AVPlayerLayer。这就是我尝试过的:
let player = AVPlayer(url: url)
let playerLayer = AVPlayerLayer(player: player)
let slideDown = UISwipeGestureRecognizer(target: self, action: #selector(dismissTest(gesture: slideDown, playerLayer: playerLayer)))
slideDown.direction = .down
addGestureRecognizer(slideDown)
这是dismissTest函数:
@objc func dismissTest(gesture: UISwipeGestureRecognizer, playerLayer: AVPlayerLayer) {
UIView.animate(withDuration: 0.4) {
if let theWindow = UIApplication.shared.keyWindow {
gesture.view?.frame = CGRect(x:theWindow.frame.width - 115 , y: theWindow.frame.height - 208, width: 100 , height: 178)
playerLayer.frame = CGRect(x:theWindow.frame.width - 115 , y: theWindow.frame.height - 208, width: 100 , height: 178)
}
}
}
然而,在尝试这个时我得到错误:
在其自己的初始值
中使用的变量
如果我不想传递AVPlayerLayer参数,这就是我的工作,它可以正常工作:
let slideDown = UISwipeGestureRecognizer(target: self, action: #selector(dismissTest(gesture:)))
slideDown.direction = .down
addGestureRecognizer(slideDown)
@objc func dismissTest(gesture: UISwipeGestureRecognizer) {
print("true")
UIView.animate(withDuration: 0.4) {
if let theWindow = UIApplication.shared.keyWindow {
gesture.view?.frame = CGRect(x:theWindow.frame.width - 115 , y: theWindow.frame.height - 208, width: 100 , height: 178)
}
}
}
当我添加AVPlayerLayer参数时,一切都搞砸了,我得到错误,比如缺少参数。如何更改函数,以便允许我传递手势参数和AVPlayerLayer参数?