简体   繁体   中英

iPad keyboard hiding textfield

This is a very common problem in which the keyboard hides the textfield . Also there is lots of solution posted on SO for this.

So currently i am referring following post which is working well in iPad portrait mode but in iPad landscape mode the the view is sliding towards left direction where as i want the view to move up.

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [self animateTextField: textField up: YES];
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self animateTextField: textField up: NO];
}

- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
    const int movementDistance = 80; // 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];
}

As iPad itself providing good options like "Undock" and "Split" for Keyboard, generally we dont need to arrange Text Field. Although considering you problem if you needed check device current orientation using [[UIDevice currentDevice] orientation] based on that animate text fields frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM