Created
November 12, 2020 17:33
-
-
Save jbadger3/7e795216b9766c72ab4e1cacb5b20517 to your computer and use it in GitHub Desktop.
iOS manual keyboard dismissal
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
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
let contentView = ContentView() | |
if let windowScene = scene as? UIWindowScene { | |
let window = UIWindow(windowScene: windowScene) | |
window.rootViewController = UIHostingController(rootView: contentView) | |
self.window = window | |
window.makeKeyAndVisible() | |
let tapGesture = UITapGestureRecognizer(target: window, action: #selector(UIView.endEditing)) | |
tapGesture.cancelsTouchesInView = false | |
tapGesture.delegate = self | |
tapGesture.name = "MyTapGesture" | |
window.addGestureRecognizer(tapGesture) | |
} | |
} | |
} | |
extension SceneDelegate: UIGestureRecognizerDelegate { | |
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment