I am trying to find which textfield is active for when the I move the view when the keyboard rises. I am trying to set a property in my viewcontroller from the subview of a
I did an extension for this.
public extension UIResponder {
private struct Static {
static weak var responder: UIResponder?
}
public static func currentFirst() -> UIResponder? {
Static.responder = nil
UIApplication.shared.sendAction(#selector(UIResponder._trap), to: nil, from: nil, for: nil)
return Static.responder
}
@objc private func _trap() {
Static.responder = self
}
}
Use:
if let activeTextField = UIResponder.currentFirst() as? UITextField {
// ...
}