Reputation: 250
I am facing some weird issue, here is my code for registering pan gesture
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
delegate method is not get called.
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
}
}
Instead, if i debug the code and print the line self.gesture.delegate
, then the delegate method is getting called.
Every time i need to print the above line to work. Please help me, thanks
Upvotes: 1
Views: 1921
Reputation: 250
For the above issue, i have fixed by adding below sharedinstace,
static let sharedInstance : PanGestureHandler = {
let instance = PanGestureHandler()
return instance
}()
And registering the pangesture for view by,
let gestureInstance = PanGestureHandler.sharedInstance
gestureInstance.registerGesture(self.view)
Upvotes: 1