Last active
December 31, 2015 17:29
-
-
Save keicoder/8020983 to your computer and use it in GitHub Desktop.
objective-c : 키보드 나타날 때 텍스트 뷰 사이즈 조정
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
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
//키보드 옵저버 | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) | |
name:UIKeyboardDidShowNotification object:self.view.window]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) | |
name:UIKeyboardWillHideNotification object:self.view.window]; | |
} | |
- (void)viewWillDisappear:(BOOL)animated | |
{ | |
[super viewWillDisappear:animated]; | |
[[NSNotificationCenter defaultCenter] removeObserver:self]; //키보드 옵저버 해제 | |
} | |
#pragma mark - 키보드 팝업 (텍스트 뷰 사이즈 조정) | |
- (void)keyboardDidShow:(NSNotification*)notification { | |
NSDictionary* d = [notification userInfo]; | |
CGRect r = [[d objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
NSNumber* curve = [d objectForKey:UIKeyboardAnimationCurveUserInfoKey]; | |
NSNumber* duration = [d objectForKey:UIKeyboardAnimationDurationUserInfoKey]; | |
r = [self.view convertRect:r fromView:nil]; | |
CGRect f = self.noteTextView.frame; | |
self->oldFrame = f; | |
f.size.height = self.view.frame.size.height - f.origin.y - r.size.height; [UIView beginAnimations:nil context:NULL]; | |
[UIView setAnimationDuration:[duration floatValue]]; | |
[UIView setAnimationCurve:[curve intValue]]; | |
self.noteTextView.frame = f; | |
[UIView commitAnimations]; | |
} | |
- (void)keyboardWillHide:(NSNotification*)notification { | |
NSDictionary* d = [notification userInfo]; | |
NSNumber* curve = [d objectForKey:UIKeyboardAnimationCurveUserInfoKey]; | |
NSNumber* duration = [d objectForKey:UIKeyboardAnimationDurationUserInfoKey]; | |
[UIView beginAnimations:nil context:NULL]; | |
[UIView setAnimationDuration:[duration floatValue]]; | |
[UIView setAnimationCurve:[curve intValue]]; | |
self.noteTextView.frame = self->oldFrame; | |
[UIView commitAnimations]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment