Τετάρτη, 23 Ιανουαρίου 2013

How to the keyboard NOT slides up overtop of a textfield

1. Add UITextFieldDelegate delegate at .h file
2. Connect from xib file your textField with file's Owner as Delegate
3.

- (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 = textField.frame.origin.y / 2; // 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];
}

the solution from stackoverflow here.

but here a comment on that
I have to mention that "If your are writing an application for iOS 4 or later, you should use the block-based methods for animating your content instead." Referenced from :developer.apple.com/library/ios/#documentation/windowsviews/…

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου