Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

dismiss keyboard when tap outside swift 5

extension UIViewController {
    func hideKeyboardWhenTappedAround() {
        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
        tap.cancelsTouchesInView = false            
        view.addGestureRecognizer(tap)
    }

    @objc func dismissKeyboard() {
        view.endEditing(true)
    }
}

//Now in every UIViewController, all you have to do is call this function:

override func viewDidLoad() {
    super.viewDidLoad()
    self.hideKeyboardWhenTappedAround() 
}
Comment

dismiss keyboard on tap outside swiftui

extension UIApplication {
    func endEditing() {
        sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) 
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: defer swift 
Swift :: swift inheritance 
Swift :: objective c vs swift 
Swift :: Equatable Function Swift 
Swift :: create button with icon swift 
Swift :: uilabel set fon siz 
Swift :: add callbacks to view swiftui 
Swift :: swiftui tutorial 
Swift :: deselect all cell in collectionview 
Swift :: swift extension Array of type 
Swift :: Swift Class and Objects 
Swift :: polymorphism in swift 
Swift :: fetch request core data 
Swift :: two value sum 
Swift :: Swift Right Shift Operator 
Swift :: initializer generator xcode swift 
Swift :: Customize indicator view iOS swift 
Swift :: swift function 
Swift :: swift conditional statements 
Swift :: Swift Dictionary Inside a Tuple 
Swift :: fullscreencover swiftui 
Swift :: swift concurrency datatask before ios 15 
Swift :: how to stack align label over a card in flutter 
Swift :: ios uikit hide/show keyboard if scrolling 
Swift :: swift get all cases starting with 
Swift :: Swift Character 
Ruby :: rails kill server 
Ruby :: rails benchmark 
Ruby :: rails g resource 
Ruby :: ruby capitalize first character of sentence 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =