0

I am havng one textfield and two textViews...while writting something in 1 conrol the keyboard is poped up...but when I want to shift on another control my keyboard doesn't let me write as it covers the whole view...hw can I solve my problem?

khushbu shah
  • 21
  • 2
  • 4
  • You mean to say keyboard covers up your text field ? Is that your problem ? – Janak Nirmal Jan 16 '12 at 13:13
  • @khushbu, you need to first learn basics of objective c.Use [this](http://iphonesdkbasics.blogspot.com/2010/01/disabling-keyboard-on-uitextfield.html) function to disable keypad for uitextfield and take help of touch event to hide keypad for uitextview as it is not disables with return key.. Also try [this,i think this is what you will like.](http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present) – Yama Puvar Jan 16 '12 at 13:10
  • @Sarah- I am doing practice work only as I am new for iPhone.and ya..I will try This... – khushbu shah Jan 17 '12 at 04:22

4 Answers4

1

you should move your view up, so that the keyboard doesnt cover the textfield/ textview. something like this...

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{   
    if (textField == *textFieldName*) 
    {
        [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 - 65.0), self.view.frame.size.width, self.view.frame.size.height);
        [UIView commitAnimations];

    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField 
{   
    if (textField == *textFieldName*) 
    {
        [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 + 65.0), self.view.frame.size.width, self.view.frame.size.height);
        [UIView commitAnimations];
    } 
}

and for the textView use:

- (void)textViewDidBeginEditing:(UITextView *)textView

and

- (void)textViewDidEndEditing:(UITextView *)textView
Sam Parrish
  • 1,357
  • 1
  • 9
  • 17
0

Use delegate functions provided for uitextview and uitextfiled ....

B25Dec
  • 2,065
  • 3
  • 29
  • 50
  • I have tried one thing...I have taken button on my whole view....So, whenever I click on any portion of my view , the keyboard will disappear...I have used "self.resignResponder"...but Not working.....can you suggest me other way? – khushbu shah Jan 16 '12 at 13:10
  • 1
    it should be [textField resignFirstResponder] – vishy Jan 16 '12 at 13:20
  • instead of self.resign responder you have to resign the responder from uitextfield or from uitextview . or checkout any tutorial using uitextfield or textview based on ios.. – B25Dec Jan 16 '12 at 13:21
0
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
    const int movementDistance = 150; // tweak as needed
    const float movementDuration = 0.3f; // tweak as needed

    int movement = (up ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{

        [self animateTextField: textField up: YES];
}
- (void)textViewDidEndEditing:(UITextView *)textView{
            [self animateTextField: textField up: NO];

}
Anil Kothari
  • 7,433
  • 4
  • 17
  • 24
0

you can shift your whole view up or just shift the controls (text field and text view) up .. or make your view scrollable so the user can scroll down while the keyboard is visible.

Malek_Jundi
  • 5,992
  • 2
  • 25
  • 35
  • even so .. you can add all of your controls inside a scroll view so if the user scroll the screen with the keyboard visible he will be able to see the other controls – Malek_Jundi Jan 17 '12 at 13:39