can any one give me example with swift programming for scrolling textfield on click when keyboard is present on uiviewcontroller
how to make a uitextfield move up when keyboard is present
can any one give me example with swift programming for scrolling textfield on click when keyboard is present on uiviewcontroller
how to make a uitextfield move up when keyboard is present
use this code
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
self.view.endEditing(true)
}
func textFieldDidBeginEditing(textField: UITextField) {
textField.keyboardType = UIKeyboardType.EmailAddress
self.animateViewMoving(true, moveValue: 50)
}
func textFieldDidEndEditing(textField: UITextField) {
self.animateViewMoving(false, moveValue: 50)
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
func animateViewMoving (up:Bool, moveValue :CGFloat){
var movementDuration:NSTimeInterval = 0.3
var movement:CGFloat = ( up ? -moveValue : moveValue)
UIView.beginAnimations( "animateView", context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(movementDuration )
self.view.frame = CGRectOffset(self.view.frame, 0, movement)
UIView.commitAnimations()
}
Use TPKeyboardAvoiding . Just set the class of Scrollview to TPKeyboardAvoidingScrollView & import the files in your code.Use the following link https://github.com/michaeltyson/TPKeyboardAvoiding