Skip to content

Instantly share code, notes, and snippets.

@projectxcappe
Created March 20, 2018 17:26
Show Gist options
  • Select an option

  • Save projectxcappe/5a41c5b14ab495df67d7821e89b76d45 to your computer and use it in GitHub Desktop.

Select an option

Save projectxcappe/5a41c5b14ab495df67d7821e89b76d45 to your computer and use it in GitHub Desktop.
//Method just for getting keyboard height
@objc func keyboardWillShow(_ notification: Notification) {
if let keyboardFrame: NSValue = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue {
let keyboardRectangle = keyboardFrame.cgRectValue
keyboardHeight = keyboardRectangle.height
}
}
func checkIfKeyboardIsOverTextField(keyboardHeight: CGFloat) {
for field in textfieldCollection {
if (field.isFirstResponder) {
print((field.frame.origin.y + field.frame.size.height))
print(keyboardHeight)
if (field.frame.origin.y + field.frame.size.height) >= keyboardHeight {
scrollView.setContentOffset(CGPoint(x:0.0,y:100), animated: true)
}
}
}
}
func textFieldDidBeginEditing(_ textField: UITextField) {
checkIfKeyboardIsOverTextField(keyboardHeight: keyboardHeight)
// if textField.frame.origin.y <= keyboardHeight {
// scrollView.setContentOffset(CGPoint(x:0.0,y:100), animated: true)
// }
// fadeOut(labelCollection: labelCollection)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment