UITextField Gesture event argument has been changed on iOS 13.4?

Hi.


UITextField Gesture event argument has been changed on iOS 13.4?

Usually, We writing this code when judge gesture type.


open override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  // is Tap
  if gestureRecognizer.isKind(of: UITapGestureRecognizer.self) {
      // code
  }
}


But gestureRecognizer.isKind method was return "false" when running on iOS 13.4.

iOS13.3 is "true".

In which type of class do you implement this override ?

This override method is defined on Custome Class of UITextField.


Minimum code is follow.


import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

class ExTextField : UITextField {
    open override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {

        if let ges = gestureRecognizer as? UITapGestureRecognizer {
            print ("true")
        } else {
            print ("false")
        }
        return true
    }
}


iOS13.4 iPhone Simulator and iOS13.4 iPad Pro(Gen2) is print("false").

iOS13.3 iPhone Simulator and iOS13.3 iPad Pro(Gen2) is print("true").

Just confirming we're seeing this as well.


When receiving taps from a UITextField what was `UITapGestureRecognizer` is now `UITextMultiTapRecognizer`, which is undocumented.

mineyuki, you could test what you get:


class ExTextField : UITextField {
    open override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {

        if let ges = gestureRecognizer as? UITapGestureRecognizer {
            print ("true")
        } else {
            print ("false. Gesture is a ", gestureRecognizer)
        }
        return true
    }
}


How did you define the gesture ? In code ? In IB ?


Just tested a tapGesture created by code:

        let tapLabelGesture = UITapGestureRecognizer(target: self, action: #selector(labelTapped(_:)))
        label.addGestureRecognizer(tapLabelGesture)


    @objc func labelTapped(_ sender: UITapGestureRecognizer) {
        aTextView.text = "Start labelTapped"
        aTextView.isHidden = false
    }


SingleTap tested

- XCode 11.4

- iOS 13.4 simulator

produces the expected result

I tried this with an iOS 13.4 device:


override public func awakeFromNib() {
  let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(receivedTap))
  addGestureRecognizer(tapRecognizer)
}

@objc func receivedTap(_ gestureRecognizer: UIGestureRecognizer) {
}
 
override public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {  
  NSLog("gestureRecognizerShouldBegin")
}

If I break in gestureRecognizerShouldBegin in the debugger I first get


po gestureRecognizer
<UITextMultiTapRecognizer: 0x144925620 (UITextInteractionNameSingleTap); state = Possible; delaysTouchesEnded = NO; view = <GreyTextField 0x150650000>; target= <(action=onStateUpdate:, target=<UITextMultiTapRecognizer 0x144925620>)>>

Followed by the UITapGestureRecognizer we are expecting.
This a behaviour change. Prior to 13.4 we would get a UITapGestureRecognizer from built-in gesture recognizers in UITextField, in 13.4 we do not and need to define the gesture directly.

UITextField Gesture event argument has been changed on iOS 13.4?
 
 
Q