Move view when keyboard displayed over uitextfield : I have looked around and found [this][1] post about moving a view when a keyboard appears. It works great, and moves the keyboard anytime I click in a UItextfield. The issue is that I Have three UITextfields, and the keyboard should only move when it is going to present over a uitextfield. I looked at the apple [documentation][2] on this as well, and found some useful but I am still not getting the desired functionality. 


 

    func keyboardWillShow(notification: NSNotification) {
        
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
    
            var aRect = self.view.frame;
            
            aRect.size.height -= keyboardSize.size.height
            
            if self.view.frame.origin.y == 0{
                if aRect.contains(activeField.frame.origin){
                    self.view.frame.origin.y -= keyboardSize.height
                }
            }
        }
    }
    
    
    func textFieldDidBeginEditing(_ textField: UITextField) {
        activeField = textField
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        activeField = nil
    }
    
    func keyboardWillHide(notification: NSNotification) {
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
            if self.view.frame.origin.y != 0{
                self.view.frame.origin.y += keyboardSize.height
            }
        }
    }

From the apple documentation I just took the piece where I create the `aRect`, and then check if the points intersect with the `contains` function. I would expect this to then make the view move only when the keyboard were to overlap with a textfield, and keep the view in place otherwise. For some reason that I don't fully understand, this is not the case. The keyboard will move the view in the case where any textfield is clicked (even though for some it shouldn't). I have played around with it a bit now and tried debugging but have been unsuccessful. Any ideas? 


  [1]: http://stackoverflow.com/questions/26070242/move-view-with-keyboard-using-swift?rq=1
  [2]: https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

