khushbu shah
khushbu shah

Reputation: 21

keyboard does not disappear from the view-iphone

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?

Upvotes: 0

Views: 414

Answers (4)

Malek_Jundi
Malek_Jundi

Reputation: 6160

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.

Upvotes: 0

Sam Parrish
Sam Parrish

Reputation: 1387

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

Upvotes: 1

Anil Kothari
Anil Kothari

Reputation: 7733

- (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];

}

Upvotes: 0

B25Dec
B25Dec

Reputation: 2377

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

Upvotes: 0

Related Questions