Created
November 26, 2017 13:36
-
-
Save sjehutch/4defbdb2123ed899cad91e4b29ff65c8 to your computer and use it in GitHub Desktop.
Swift 3 move keyboard up textfield
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func animateTextField(textField: UITextField, up: Bool) | |
{ | |
let movementDistance:CGFloat = -130 | |
let movementDuration: Double = 0.3 | |
var movement:CGFloat = 0 | |
if up | |
{ | |
movement = movementDistance | |
} | |
else | |
{ | |
movement = -movementDistance | |
} | |
UIView.beginAnimations("animateTextField", context: nil) | |
UIView.setAnimationBeginsFromCurrentState(true) | |
UIView.setAnimationDuration(movementDuration) | |
self.view.frame = self.view.frame.offsetBy(dx: 0, dy: movement) | |
UIView.commitAnimations() | |
} | |
func textFieldDidBeginEditing(textField: UITextField) | |
{ | |
self.animateTextField(textField: textField, up:true) | |
} | |
func textFieldDidEndEditing(textField: UITextField) | |
{ | |
self.animateTextField(textField: textField, up:false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment