I\'m trying to set the animation for the view to move up when keyboard is hiding and appearing for the text fields and I got it to work perfectly fine, but when the focus moves
-(BOOL)textFieldShouldBeginEditing:(UITextField*)textField {
if (textField.tag == 1) { //first textField tag
//textField 1
}
else {
//textField 2
}
}
Use UITextFieldDelegate
and
func textFieldDidBeginEditing(textField: UITextField) {
println("did")
if textField.tag == 1{
self.txtFullName.layer.borderColor = UIColor.blueColor().CGColor
}
}
Use the UITextField
delegate methods .. its better on your case than the keyboard methods .. when textField got focus the - (void)textFieldDidBeginEditing:(UITextField *)textField;
will be fired .. and when it lost focus - (void)textFieldDidEndEditing:(UITextField *)textField;
will be fired.
In swift 4:
UITextFieldDelegate
into your ViewController
classtextFields
you want to detect focus ontextFieldDidBeginEditing
(in case you want to be notified on that specific action, see Apple's documentation) and fill it with your codeviewDidLoad()
assign your ViewController
class as the delegate for the textField
you previously added in step 2It must look similar to:
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var yourTextField: UITextField!
func textFieldDidBeginEditing(_ textField: UITextField) {
// Your code here
}
override func viewDidLoad() {
super.viewDidLoad()
yourTextField.delegate = self
}
...
}