0

Whenever I click on textfield, keyboard pops up and partially blocked other textfields as seen in the image, how could I manage it? I want whenever last textfield on the right bottom filled, then second row should be up and visible ! By the way, Scroll view on the top of ViewController.

-(void)ViewDidLoad
{
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];

}
 - (void)keyboardDidShow:(NSNotification *)notification
    {
             [self.view setFrame:CGRectMake(0,-260,1030,768)]; 
    }

-(void)keyboardDidHide:(NSNotification *)notification
{
    [self.view setFrame:CGRectMake(0,0,1030,768)];

}

enter image description here

casillas
  • 14,727
  • 15
  • 94
  • 183

3 Answers3

0

Wrap your view in an UIScrollView!

faffaffaff
  • 3,016
  • 13
  • 25
0

You need to setup observation of UIKeyboardWillChangeFrameNotification and UIKeyboardDidChangeFrameNotification or UIKeyboardDidShowNotification and UIKeyboardDidHideNotification. When you receive the notifications you will have the trigger to move/resize the content of your view and the size of the keyboard that's being displayed so you know how much to move/resize it.


You may also find it useful to act as the delegate of the text fields and implement textFieldDidBeginEditing:. When this method is called you know that the supplied text field should be visible. You can get the frame of the text field (which you may need to translate if there are multiple superviews before you get to the scroll view) and use it to scrollRectToVisible:animated: (or just set the contentOffset).

Wain
  • 117,132
  • 14
  • 131
  • 151
  • how do you differentiate between first row completed and move to second row? – casillas Jun 27 '13 at 20:44
  • Check if values have been entered or not – HM1 Jun 27 '13 at 20:45
  • You can also be the delegate of the text fields so that you can scroll their frames to visible. – Wain Jun 27 '13 at 20:46
  • @Wain, how? is there any resources that I refer? – casillas Jun 27 '13 at 20:48
  • @HM1, how do we check values entered or not? – casillas Jun 27 '13 at 20:48
  • @casillas Use mytextfield1.text and check if its empty or has characters. But the bigger question is when do you want to check for the value and what are you going to do? Having the scrollview, the user can scroll around to the next fields as needed. – HM1 Jun 27 '13 at 20:54
0

You need to change the view size when the keyboard comes up and change it back when keyboard disappears. Use a scrollview and the keyboard notification or textfield delegate methods for when keyboard appears/disappears.

HM1
  • 1,654
  • 1
  • 18
  • 25