我有两个 UISliders ,并且已为其附加一个 UIPanGestureRecognizer 。 当我平移 episodeSlider 时, soundSlider 没有任何反应,但是当我平移 soundSlider 时, episodeSlider 的行为就像我正在与之交互它和缩略图恰好在 episodeSlider 的开头。
class PlayerDetailsView: UIView {
...
@IBOutlet weak var episodeSlider: UISlider! {
didSet {
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panTap(gesture:)))
episodeSlider.isContinuous = true
episodeSlider.addGestureRecognizer(panGesture)
episodeSlider.setValue(0, animated: false)
}
}
@IBOutlet weak var volumeSoundSlider: UISlider! {
didSet {
volumeSoundSlider.isContinuous = true
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panTapVolume(gesture:)))
volumeSoundSlider.isContinuous = true
volumeSoundSlider.addGestureRecognizer(panGesture)
player.volume = volumeSoundSlider.value
}
}
@objc func panTap(gesture : UIPanGestureRecognizer){
print(type(of: gesture.view), gesture.view)
if gesture.view != episodeSlider {
return
}
...
}
@objc func panTapVolume(gesture : UIPanGestureRecognizer) {
print(type(of: gesture.view), gesture.view)
if gesture.view != volumeSoundSlider {
return
}
...
}
但是 PanTap 函数绝不会使用错误的参数调用(因此,这些函数内部的 return 永远不会执行),所以我不知道如何处理它。
我尝试使用 UIGestureRecognizerDelegate 做一些魔术,但是我没有找到合适的功能。