UITapGestureRecognizer issue in iOS 9

前端 未结 3 793
耶瑟儿~
耶瑟儿~ 2021-02-19 09:10

I guys,

today I\'ve updated my iPhone to iOS 9 and now have problems with a gesture recognizer. This is the error:

WARNING: A Gesture recognizer (

相关标签:
3条回答
  • 2021-02-19 09:43

    I think that this problem happen when you use storyboard added a Tap Gesture Recognizer. Because some reasons you added more than one views.(see the picture).

    So, delete other wrong views,leave the right one view.

    0 讨论(0)
  • 2021-02-19 09:47

    Already fixed it. The storyboard is localized and in one language I assigned the the recognizer twice to the picture view. Somehow this seemed to cause troubles on the other storyboards too.

    0 讨论(0)
  • 2021-02-19 09:59

    This was happening with me because I wanted to use a Tap Gesture Recognize with an image in a TableViewCell contained in a TableView.

    The problem is that:

    I add one Tap Gesture Recognizer but I have more than one TableViewCell (more than one image) in my table.

    iOS will assign the UITapGestureRecognizer to the first image in the first cell, and other cells will be without gestures (the gesture already set to the first image only).

    To Solve this problem follow this:

    1. Make sure you checked User Interaction Enabled for the UIView you want to assign with a TapRecognizerGesture.
    2. in the sub-view TableViewCell in my case add a new UITapGestureRecognizer. The code:

      internal let tapRecognizer1: UITapGestureRecognizer = UITapGestureRecognizer()`
      
    3. In your main view TableView in my case and for every cell assign the UITapGestureRecognizer you made with each cell to a main function in the main view:

      cell.tapRecognizer1.addTarget(self, action: "img_Click:")
      cell.img.gestureRecognizers = []
      cell.img.gestureRecognizers!.append(cell.tapRecognizer1)
      
    4. Add the function you want UITapGestureRecognizer to fire when clicked:

      func img_Click(sender: UITapGestureRecognizer) {
          print("ok")
      }
      

    Notes:

    • You can use simple way if you do not want the UITapGestureRecognizer action in the main view by assigning it in its sub-view directly.
    • in step 4 function name must be the same as in addTarget line.
    0 讨论(0)
提交回复
热议问题