Suppose you need to move the view to a text field whose tag is 4 (if you have more than 1 txt field and one of them is closed by the keyboard), use the textField delegation method
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { if(textField.tag==4) CGRect viewFrame; viewFrame=self.view.frame; if(viewFrame.origin.y==-100) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; viewFrame.origin.y+=100; self.view.frame=viewFrame; [UIView commitAnimations]; } }
it moves your presentation. now to move down you need the code in the textField anothe delegate method
- (BOOL)textFieldShouldReturn:(UITextField *)textField { if(textField.tag==4) { CGRect viewFrame; viewFrame=self.view.frame; if(viewFrame.origin.y==-100) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; viewFrame.origin.y+=100; self.view.frame=viewFrame; [UIView commitAnimations]; } } }
In the case of text viewing, you need to click a button, and to move up you need this delegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
and use the same code as textField
And moving down, you need a button on the navigation bar or add a toolbar and set this toolbar above the keyboard using the same animation. For the button, you need the same code to move down that is applicable to textField.
Hope this helps you.
source share