1

i am working with an app which takes signature in image view. and im using SWRevealViewController for side menu. my app looks like this.

enter image description here

     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.

AtulParmar
  • 4,358
  • 1
  • 24
  • 45
Ravi
  • 165
  • 3
  • 11

5 Answers5

0

Have you tried setting isUserInteractionEnabled to true on the UIImageView?

Brandon Stillitano
  • 1,304
  • 8
  • 27
0

If you want to disable the gesture for a specific view.

self.<yourview>.isUserInteractionEnabled = false
SAIF
  • 126
  • 8
0

You can adjust the property on Reveal controller.

revealController.draggableBorderWidth = # Your Value #

It will restrict the reveal controller to start the pan gesture if the start of touch is less than this value. Like in your case your if your image view x location is 50. So you can set this property to 40. Than pan gesture will work when the user touch location is less than 40. By default its value is 0 that's why the pan gesture starts from anywhere.

0

SWRevealViewController provides this functionality. Just write revealViewController().panGestureRecognizer().isEnabled = false in the controller you want to disable the functionality to open the menu.

palme
  • 2,499
  • 2
  • 21
  • 38
0

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

RJ168
  • 1,006
  • 2
  • 12
  • 22