Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: How to adjust height of area covered by keyboard in iOS

Tags:

ios

keyboard

Im curious about a feature in iOS. Please help me out here if you can.

Scenario: I am using a text box where name is entered. Its on lower half of the screen. Just below the text box is a label which displays the number of characters remaining(e.g.like in a twitter feed).

Problem: When i place the text box in upper half of the screen. both the text field and label are visible. But when I place them in lower half, the apple keyboard covers the label part. Is there a way where I control the area covered in such a way that the label below is also visible? I hope I have made myself clear enough. Thanks.

like image 464
na19 Avatar asked Dec 26 '22 23:12

na19


1 Answers

Here i have used delegate method for UITextView Same way you can do for UITextField

-Here in this code when user starts entering values in textview it makes your view's hight lesser then its original with animation

-When user Ends Entering values, it will make your view's size original size.

-(void)textViewDidBeginEditing:(UITextView *)textView
{

    CGRect frame = self.view.frame;
    frame.origin.y = -100;
    [self.view setFrame:frame];
    [UIView commitAnimations];
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
    CGRect frame = self.view.frame;
    frame.origin.y = 0;
    [self.view setFrame:frame];
    [UIView commitAnimations];

 }

If you want to know about delegates this link helps you

like image 96
Chitra Khatri Avatar answered Feb 23 '23 02:02

Chitra Khatri