How can i move textView
/textField
to top of view when I select one of them?
Asked
Active
Viewed 1,681 times
-3

rmaddy
- 314,917
- 42
- 532
- 579
-
2Google is a developer's best friend. – Dhrumil Aug 13 '14 at 09:15
1 Answers
2
Working code....
1) set delegate
to you textFields
[self.textField setDelegate:self];
2) To move textField
up
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == self.textField)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x , (self.view.frame.origin.y - 80), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
}
3) To move textField
down
-(void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == self.textField)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x , (self.view.frame.origin.y + 80), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
}
4) to move textView
Up
-(void)textViewDidBeginEditing:(UITextView *)textView
{
if (textView == self.textView)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x , (self.view.frame.origin.y - 80), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
}
5) to move textView
Down
-(void)textViewDidEndEditing:(UITextView *)textView
{
if (textView == self.textView)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x , (self.view.frame.origin.y + 80), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
}

Ty Lertwichaiworawit
- 2,950
- 2
- 23
- 42