i am working with an app which takes signature in image view. and im using SWRevealViewController for side menu. my app looks like this.
class CaptureSignature: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIGestureRecognizerDelegate {
im writing below code to show side menu
override func viewDidLoad() {
super.viewDidLoad()
let revealViewController = self.revealViewController()
menuBtn.addTarget(revealViewController, action: #selector(SWRevealViewController.rightRevealToggle(_:)), for: .touchUpInside)
revealViewController?.panGestureRecognizer()?.isEnabled = true
}
now my problem is, while im swiping on image view from right to left, instead of drawing a line, side menu is opening.(because i have enabled panGesture in SWRevealViewController).
What i dont want is, i dont want to enable swipe gesture on imageView to show menu bar when i swipe right. i wrote the below func but its not working(even it is not entering into method when i put breakpoints in it)
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
if let touchedView = touch.view, touchedView.isDescendant(of: imageView) {
print("touched in image view")
return false
}
return false
}
can any one help me please.
You can ignore the swipe gesture for particular area using following method.
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool
and still you can call touchesMoved
to draw your signature. Here is the sample code.
func addSwipeGesture() {
let leftSwipe = UISwipeGestureRecognizer(target: self, action:
#selector(handleSwipes(_:)))
leftSwipe.delegate = self
let rightSwipe = UISwipeGestureRecognizer(target: self, action:
#selector(handleSwipes(_:)))
rightSwipe.delegate = self
leftSwipe.direction = .left
rightSwipe.direction = .right
self.view.addGestureRecognizer(leftSwipe)
self.view.addGestureRecognizer(rightSwipe)
}
@objc func handleSwipes(_ sender:UISwipeGestureRecognizer) {
if (sender.direction == .left) {
print("Swipe Left")
}
if (sender.direction == .right) {
print("Swipe Right")
}
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive
touch: UITouch) -> Bool {
return !self.imgView.bounds.contains(touch.location(in: self.imgView))
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
print("moving")
}
For the above code snippet, swipe will get ignored for image view i.e. imgView