我面临一些奇怪的问题,这是我的注册平移手势的代码
<div class="row">
<ul class="nav nav-tabs nav-justified" role="tablist">
<li role="presentation" class="active"><a href="#" aria-controls="" role="tab" data-toggle="tab">test1</a></li>
<li role="presentation"><a href="#" aria-controls="" role="tab" data-toggle="tab">test2</a></li>
<li role="presentation"><a href="#" aria-controls="" role="tab" data- toggle="tab">test3</a></li>
</ul>
</div>
public func registerGesture(_ view: UIView) {
self.gesture = UIPanGestureRecognizer(target: self, action: #selector(handleGesture(_:)))
self.gesture?.minimumNumberOfTouches = 1
self.gesture?.maximumNumberOfTouches = 1
self.gesture?.delegate = self
view.addGestureRecognizer(self.gesture!)
}
委托方法未被调用。
UIPanGestureRecognizer
}
相反,如果我调试代码并打印行extension PanGestureHandler : UIGestureRecognizerDelegate {
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
guard let g = self.gesture else { return false }
guard g.view is UIScrollView else { return false }
return true
}
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy
otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return false
}
,则会调用委托方法。
每次我需要打印上述线路才能工作。请帮帮我,谢谢
答案 0 :(得分:1)
对于上述问题,我通过添加以下sharedinstace修复了
static let sharedInstance : PanGestureHandler = {
let instance = PanGestureHandler()
return instance
}()
注册pangesture以供查看,
let gestureInstance = PanGestureHandler.sharedInstance
gestureInstance.registerGesture(self.view)