Mehul Patel
Mehul Patel

Reputation: 23053

Check UITextField is visible but behind the keyboard

Work around:

UIViewController contains UITableview with custom cell. Each cell contains cusom UIView with UITextField.

We all know that it is possible to manage UITextField delegates and make UIView up/down to show UITextField that are not visible when keyboard appears.

Problem:

Here content of UITableView is dynamic, its decided runtime that which cell contains UITextField. I have tried many solution for keyboard up/down views. But still some issues remains.

So now decided to make a translation only for that UITextField which are not appear on screen or behind the keyboard.

Is there any way to know that UITextField which is responder of keyboard appearance is behind the keyboard or its above the keyboard?

Any better approach?

Please add a comment if question is unclear.

Upvotes: 0

Views: 878

Answers (2)

Rajesh
Rajesh

Reputation: 10424

Instead of checking all this you can reframe the tableView when keyboard is visible.

In viewDidLoad() add this

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow) name:UIKeyboardDidShowNotification object:nil];

in receiver set the new frame

 - (void)keyboardShow{
        [tableView setFrame:newFrame]
    }

again in name:UIKeyboardDidHideNotification reset to initial frame when keyboard is not there

Upvotes: 1

Retro
Retro

Reputation: 4005

Based on the current textField frame y position you can check is that is it behind the keyboard or not using

-(void)textFieldDidBeginEditing:(UITextField *)textField {

    CGPoint textFieldPosition = [textField convertPoint:CGPointZero toView:self.tableView];
}

now check the y value and move your UIVIew based on y value..

Upvotes: 1

Related Questions