Created
February 3, 2015 08:01
-
-
Save goshmx/5306de7340188ef1b939 to your computer and use it in GitHub Desktop.
Codigo para animar el UIView cuando el teclado oculta el input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Recuerda incluir UITextViewDelegate en tu archivo.h y hacer un delegate al input self.inputEstado.delegate = self; | |
- (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 | |
{ | |
int animatedDistance; | |
int moveUpValue = textField.frame.origin.y+ textField.frame.size.height; | |
UIInterfaceOrientation orientation = | |
[[UIApplication sharedApplication] statusBarOrientation]; | |
if (orientation == UIInterfaceOrientationPortrait || | |
orientation == UIInterfaceOrientationPortraitUpsideDown) | |
{ | |
animatedDistance = 216-(460-moveUpValue-5); | |
} | |
else | |
{ | |
animatedDistance = 162-(320-moveUpValue-5); | |
} | |
if(animatedDistance>0) | |
{ | |
const int movementDistance = animatedDistance; | |
const float movementDuration = 0.3f; | |
int movement = (up ? -movementDistance : movementDistance); | |
[UIView beginAnimations: nil context: nil]; | |
[UIView setAnimationBeginsFromCurrentState: YES]; | |
[UIView setAnimationDuration: movementDuration]; | |
self.view.frame = CGRectOffset(self.view.frame, 0, movement); | |
[UIView commitAnimations]; | |
} | |
} | |
-(BOOL)textFieldShouldReturn:(UITextField *)textField { | |
[textField resignFirstResponder]; | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment