0

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

  • possible duplicate of [Move View up/down with Keyboard ios](http://stackoverflow.com/questions/28271236/move-view-up-down-with-keyboard-ios) and http://stackoverflow.com/questions/28110886/uiview-automatically-moving-by-uitextfield-keyboard/28111208#28111208 – Wez Apr 08 '15 at 12:16
  • Please see http://stackoverflow.com/questions/26255151/ios-8-move-uiview-up-when-keyboard-appears-issue/26262072#26262072 as I have answered this question here. – iAnurag Apr 08 '15 at 12:24
  • Hello, and welcome to Stack Overflow. We are glad to help you debug code or answer questions about difficult concepts but questions as broad as this one aren't a good fit for our format. – Dustin Apr 08 '15 at 16:09

2 Answers2

0

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()
}
Rizwan Shaikh
  • 2,824
  • 2
  • 27
  • 49
0

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

poojathorat
  • 1,200
  • 2
  • 9
  • 19