Created
April 8, 2011 02:47
-
-
Save logicaroma/909193 to your computer and use it in GitHub Desktop.
Object-C iOS
This file contains 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
- (void)viewDidLoad | |
{ | |
[[NSNotificationCenter defaultCenter] | |
addObserver:self | |
selector:@selector(keyboardWillShow:) | |
name:UIKeyboardWillShowNotification | |
object:nil]; | |
[[NSNotificationCenter defaultCenter] | |
addObserver:self | |
selector:@selector(keyboardWillHide:) | |
name:UIKeyboardWillHideNotification | |
object:nil]; | |
} | |
- (void)dealloc | |
{ | |
[[NSNotificationCenter defaultCenter] removeObserver:self]; | |
} | |
- (void)keyboardWillShow:(NSNotification *)notification { | |
CGRect start, end; | |
// position of keyboard before animation | |
[[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&start]; | |
// and after.. | |
[[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&end]; | |
double duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | |
int curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]; | |
// slide view up.. | |
[UIView beginAnimations:@"foo" context:nil]; | |
[UIView setAnimationDuration:duration]; | |
[UIView setAnimationCurve:curve]; | |
self.view.frame = CGRectMake(0, -end.size.width, 480, 320); | |
[UIView commitAnimations]; | |
} | |
- (void) keyboardWillHide:(NSNotification *)notification { | |
double duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | |
int curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]; | |
// slide view down | |
[UIView beginAnimations:@"foo" context:nil]; | |
[UIView setAnimationDuration:duration]; | |
[UIView setAnimationCurve:curve]; | |
self.view.frame = CGRectMake(0, 0, 480, 320); | |
[UIView commitAnimations]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment