Last active
December 29, 2018 01:22
-
-
Save edwardean/1325912b3bfda284782fb7cda0d40bcf to your computer and use it in GitHub Desktop.
Find the first Responder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
private weak var currentFirstResponder: AnyObject? | |
extension UIResponder { | |
@objc func findFirstResponder() -> AnyObject? { | |
currentFirstResponder = nil | |
UIApplication.shared.sendAction(#selector(findFirstResponder(_:)), to: nil, from: self, for: nil) | |
return currentFirstResponder | |
} | |
@objc static func findFirstResponder() -> AnyObject? { | |
currentFirstResponder = nil | |
UIApplication.shared.sendAction(#selector(findFirstResponder(_:)), to: nil, from: nil, for: nil) | |
return currentFirstResponder | |
} | |
@objc fileprivate func findFirstResponder(_ sender: AnyObject) { | |
currentFirstResponder = self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment