0

I have multiple UITextFields and i need to move view up when keyboard appears. But I need to it only for 3 of bottom fields and doesn't want to move view for other field on top. I use this code, but its move view when user tap on every field, instead i need move view only when user tap on 2 bottom fields

- (void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } #pragma mark - keyboard movements - (void)keyboardWillShow:(NSNotification *)notification { [UIView animateWithDuration:0.3 animations:^{ CGRect f = self.view.frame; f.origin.y = -115.0f; //set the -35.0f to your required value self.view.frame = f; }]; } -(void)keyboardWillHide:(NSNotification *)notification { [UIView animateWithDuration:0.3 animations:^{ CGRect f = self.view.frame; f.origin.y = 0.0f; self.view.frame = f; }]; } 
3

3 Answers 3

5

You can change the frame of any UIViews,UIButton.... inside UITextfield delegate method textFieldDidBeginEditing:This delegate will call when you tap on the textfield

 - (void)textFieldDidBeginEditing:(UITextField *)textField{ //here you will get the selected textfield //check whether the textfield is equal to any of three bottom field if(textfield==BottomTextfield) { //here you can change the frame of the UIViews } } 
Sign up to request clarification or add additional context in comments.

Comments

0

You need to change the UIView's frame using the UITextField's delegate methods:

- (void)textFieldDidBeginEditing:(UITextField *)textField { int tag = textField.tag; int section = tag / 1000; tag -= 1000 * section; section -= 1; CGPoint point = [[textField superview] convertPoint:textField.center toView:self.view]; CGPoint contentOffset = tableView.contentOffset; if (IOS_7) { contentOffset.y += (point.y - 230); // Adjust this value as you need } else{ contentOffset.y += (point.y - 150); // Adjust this value as you need } currentY = contentOffset.y; [tableView setContentOffset:contentOffset animated:YES]; } - (void)textFieldDidEndEditing:(UITextField *)textField { [tableView setContentOffset:CGPointMake(0, 0)]; } 

Hope this helps...!!!

Comments

0

You can check first responder (active text field). This SO answer shows how to do it: https://stackoverflow.com/a/1823360/2486394 . And move view only for some text fields.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.