0

I want to recognizer an UITapGesture (add this gesture at self.view) only in left half in my self.view (landscape) what's the way to do it?

1

2 Answers 2

2

I think the easiest way to do this is to test for this in your gesture recognizer handling method. So when you detect the double tap have a conditional that tests to see if your origin point (which you can get from the reconigzer's locationInView method) has an X value that is less than half your view's width. If it does you know the tap is on the left hand side, and then you can proceed.

2
  • finally I use gesture point, and two views, then if gesture point is inside one of these views I do an action and I solve my problem Jan 17, 2012 at 12:07
  • That's another option, although if you don't fancy messing around with multiple views doing the math is probably the easier method.
    – lxt
    Jan 17, 2012 at 14:29
0
@objc func doubleTapped() {
        if doubleTapGesture.location(in: self.view).x >= self.view.frame.width / 2 {
            print("DEBUG: Double tapped on the right side")
        } else {
            print("DEBUG: Double tapped on the left side")
        }
    }
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 6, 2022 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.