Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

move view controller to make space for keyboard swift 5

override func viewDidLoad() {
    super.viewDidLoad()            
    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}

@objc func keyboardWillShow(notification: NSNotification) {
    if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
        if self.view.frame.origin.y == 0 {
            self.view.frame.origin.y -= keyboardSize.height
        }
    }
}

@objc func keyboardWillHide(notification: NSNotification) {
    if self.view.frame.origin.y != 0 {
        self.view.frame.origin.y = 0
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: swift how to wait in a loop 
Swift :: Create enum of Errors Swift 
Swift :: set color of indicator line in collectionview swift 
Swift :: how to debug before app launch swift 
Swift :: how to screen record swift stackoverflow 
Swift :: Swift Autoclosure 
Swift :: how to scroll to section in tableview swift 
Swift :: Access Array Elements Using Swift Range 
Swift :: uiviewcontroller title color 
Swift :: separator style swiftui list 
Swift :: swift core data order by 
Swift :: how to print body moya swift 
Swift :: continue keyword in swift language 
Swift :: swift concurrency datatask before ios 15 
Swift :: how to decode optional bool swift 
Swift :: how request prefix of string in swift 
Swift :: Swift mutating Methods 
Swift :: swift writing to ios logs 
Swift :: swift 5 macos close app 
Swift :: declare empty dictionary in swift 
Ruby :: rails include route helpers in console 
Ruby :: ruby get current datetime utc 
Ruby :: convert string to hash ruby 
Ruby :: ruby file write 
Ruby :: ruby regexp match all 
Ruby :: table name from rails console 
Ruby :: auto load path rails 
Ruby :: ruby downcase 
Ruby :: random datetime ruby 
Ruby :: ruby array randomly display 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =