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 :: swift push view controller programmatically 
Swift :: Module compiled with Swift 5.3 cannot be imported by the Swift 5.3.1 compiler 
Swift :: swift hello world 
Swift :: swift sort array 
Swift :: change font swiftui 
Swift :: iOS & Swift - The Complete iOS App Development Bootcamp 
Swift :: uibutton swift set title color 
Swift :: how to covert a string into a float in swift 
Swift :: swift pop view controller 
Swift :: swift get slected row data in tableview cell 
Swift :: xcode how to know which textfield is selected 
Swift :: swiftui font add 
Swift :: Swift Create an Empty Set 
Swift :: how to clear text file swift 
Swift :: How to convert String into Array of character 
Swift :: swiftui datepicker text color 
Swift :: swift function declaration 
Swift :: swiftui image aspect ratio 
Swift :: declare variable in swif 
Swift :: bold world in text swift 
Swift :: Swift enum With Associated Values 
Swift :: swift weekday component values 
Swift :: Closure as function parameter 
Swift :: Swift self property 
Swift :: change multiplier programactlilly ios swift 
Swift :: Swift String and Character Literals 
Swift :: ln -s ~/.platformio/penv/bin/platformio /usr/local/bin/platformio ln -s ~/.platformio/penv/bin/pio /usr/local/bin/pio ln -s ~/.platformio/penv/bin/piodebuggdb /usr/local/bin/piodebuggdb 
Swift :: xcode enable a button after a text field is filled 
Swift :: sizetofit not working swift 
Ruby :: ruby raise error 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =