Search code examples
iosobjective-cui-design

How to move View up when Keyboard appeared in small screen like 4s , 5 and 5s but view should not move up when its enter inside iphone 6


How to move View up when Keyboard appeared in small screen like 4s, 5 and 5s but view should not move up when its enter inside iphone 6 and 6S.

I am sharing my code which is i have done in my app for all screen but in my condition view should not move up when its enter in 6 or 6s.

-(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 = -60; // tweak as needed
    const float movementDuration = 0.3f; // tweak as needed

    int movement = (up ? movementDistance : -movementDistance);

    [UIView beginAnimations: @"animateTextField" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];
    self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    [UIView commitAnimations];
}

Solution

  • I suggest you use IQKeyboardManager It will manage everything for you with less efforts