Search code examples
iphoneobjective-cios6uitextviewuitextviewdelegate

Keyboard covering textview on iPhone


I am newbie for iPhone application. Below is what I have...

enter image description here

When I enter Item name, I get proper screen with Done option. When I click Done, keyboard get hided.

enter image description here

Same happen for Time also.

Now when I click on description and type something, I get screen as below.

enter image description here

Now my problem is, I can't see UITextView and because of that I can't see what I am typing.

How can I show the UITextView so that I can see what I am typing.


Update 1

enter image description here


Solution

  • First take these whole controls in UIScrollView and set as it is,

    after just in UITextView delegate method textViewDidBeginEditing set the frame of view like bellow...

    -(void)textViewDidBeginEditing:(UITextView *)textView
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.3];
        yourScrollView.frame = CGRectMake(yourScrollView.frame.origin.x, -160, yourScrollView.frame.size.width, yourScrollView.frame.size.height);
        [UIView commitAnimations];
    
    }
    

    and also set same like before after return like bellow...

    -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
        if ([text isEqualToString:@"\n"]) 
        {
            [textView resignFirstResponder];
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.3];
    
            yourScrollView.frame = CGRectMake(yourScrollView.frame.origin.x, 0, yourScrollView.frame.size.width, yourScrollView.frame.size.height);
            [UIView commitAnimations];
            return NO;
        }
        return YES;
    }
    

    you can also set the frame of UIView instead of UIScrollView..

    Also first give the Delegate to UITextView and add this delegate in .h file

    i hope this helpful to you...