Get an object what bring keyboard popped.
extension UIResponder {
private weak static var currentFirstResponder: UIResponder? = nil
public static var current: UIResponder? {
currentFirstResponder = nil
UIApplication.shared.sendAction(#selector(findFirstResponder(sender:)), to: nil, from: nil, for: nil)
return currentFirstResponder
}
@objc internal func findFirstResponder(sender: AnyObject) {
UIResponder.currentFirstResponder = self
}
}
and, use like this.
UIResponder.current