Reputation: 3453
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?
Upvotes: 0
Views: 7203
Reputation: 1
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.
Upvotes: 0
Reputation: 2562
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
Upvotes: 0
Reputation: 7079
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
Upvotes: 1
Reputation: 26390
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.
Upvotes: 0
Reputation: 5541
Consider using a UITableViewController. Otherwise implement UITextFieldDelegate
and move your UIView to the desired position in the - (void)textFieldDidBeginEditing:(UITextField *)textField
method.
Upvotes: 3
Reputation: 3754
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
Upvotes: 0