sumit
5/24/2019 - 5:53 AM

keyboard avoid

show the view that is cutted bykeyboard popup while writing, by sliding or changing view

1. IHKeyboardAvoiding: 
  import IHKeyboardAvoiding
  override func viewDidAppear(_ animated: Bool) {
        KeyboardAvoiding.avoidingView = self.view
    }
  Source: https://cocoapods.org/pods/IHKeyboardAvoiding

2. Search Keyboard avoid on https://cocoapods.org 
	a. add  
class ChatViewController: UIViewController, UITextFieldDelegate
	a. add your class as delegate in viewDidLoad method
	messageTextfield.delegate = self as
	b. add your text field delegate methods
	height of keyboard : 258 points
	height of messageField = height of keyboard + height of your view
	//TODO: Declare textFieldDidBeginEditing here:
	    func textFieldDidBeginEditing(_ textField: UITextField) {
	        
	        UIView.animate(withDuration: 0.5) {
	            self.heightConstraint.constant = 308 //update height
	            self.view.layoutIfNeeded() // update the constraints of view and redraw it if needed
	        }
	        
	    }
	  
	    
	    // this below method is not automatically called as above method it needs to be called
	    //TODO: Declare textFieldDidEndEditing here:
	    func textFieldDidEndEditing(_ textField: UITextField) {
	        UIView.animate(withDuration: 0.5) {
	            self.heightConstraint.constant = 50 //update height
	            self.view.layoutIfNeeded() //update the constraints of view and redraw it if needed
	        }
	    }
	
	// call textFieldDidEndEditing method
		add the following in viewDidLoad method
			//TODO: Set the tapGesture here:
		        let tapGesture =  UITapGestureRecognizer(target: self, action: #selector(tableViewTapped))
		        // add tap gessture to table view
		        messageTableView.addGestureRecognizer(tapGesture)
		
		decalare this function
			func tableViewTapped(){
			        messageTextfield.endEditing(true)
    }