Created
August 29, 2018 22:06
-
-
Save RustyKnight/dcafdae3638b7c90bb24b4646d7c7c7f to your computer and use it in GitHub Desktop.
Extension to find which view is currently the first responder - this only works if the responder is the current view or a child of the current view
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 Foundation | |
import UIKit | |
extension UIView { | |
var firstResponder: UIView? { | |
guard !isFirstResponder else { | |
return self | |
} | |
for view in subviews { | |
guard let responder = view.firstResponder else { | |
continue | |
} | |
return responder | |
} | |
return nil | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment