0

I have an application in which I have 2 textfields and a textview. When I click on the first textfield my keyboard popsup and theirs is no problem but when I type in the second textfield my keyboard popsup and covers the textfield.

I want that when I click on the second text field, the textfield should move up little bit so that I can type in and I have a textview. But I have written code for textview so that when I type in textview it automatically moves.

The problem is with textfield. How can I solve this problem?

6 Answers 6

3

Consider using a UITableViewController. Otherwise implement UITextFieldDelegate and move your UIView to the desired position in the - (void)textFieldDidBeginEditing:(UITextField *)textField method.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for recommending UITableViewController - I can not emphasize enough how much more convenient it is when implementing forms.
This is not the best answer since textFieldDidBeginEditing can be called if the user uses a Bluetooth keyboard, and there is no need for any scrolling. YOu should instead watch keyboard notification events to detect the presence of a keyboard.
1

Check out the link below - the solution is written by Micheal Tyson. It addresses UITableView and UIScrollView, can be easily changed and works just as a drop-in component. I'm using it and it works well.

A drop-in universal solution for moving text fields out of the way of the keyboard

1 Comment

Hi delirus, i have gone through the link you mentioned in your answer but i have a problem ,the keyboard remains intact through the entire application.It does not resigns even if the textfield has endediting
0

Create two methods like given below , first one is for bringing the view slightly upwards, and second one is to bring the view to its original position back

First method:

 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, -175); [UIView commitAnimations]; 

Second method:

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:.3]; self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, 175); [UIView commitAnimations]; [self.destext resignFirstResponder]; 

Call these methods on textfieldEditingDidbegin and DidEndonExit

Comments

0

Add the view to a UIScrollView. Then use the UITextFieldDelegate methods to set the contentOffset of the scrollView when textField is tapped. Reset the contentOffset when the user has finished entering text.

Comments

0

I have created a simple subclass of UIView containing UITextView and a send button that moves up when keyboard shows and moves down when keyboard hides. In addition to that, UITextView resizes according to the amount of text in it.

Have a look at here:

https://github.com/kerrygrover/KBTextView

enter image description here

Comments

0

An obvious one that you've probably tried already, but one that took me a while to latch onto, is to change from landscape to portrait.

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.