Last active
August 29, 2015 13:57
-
-
Save keicoder/9359997 to your computer and use it in GitHub Desktop.
objective-c : modify textView size when keyboard appears
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
//modify textView size when keyboard appears and disappears | |
//Add the following instance variable to NoteEditorViewController.m | |
@implementation NoteEditorViewController | |
{ | |
//... | |
CGRect _textViewFrame; //used to store the current text view frame | |
} | |
//update viewDidLayoutSubviews to make use of this newly added instance variable | |
- (void)viewDidLayoutSubviews | |
{ | |
//called to notify the view controller that view has just laid out subviews | |
//... | |
_textView.frame = _textViewFrame; | |
} | |
//add the following to the bottom of viewDidLoad to set the initial frame value | |
- (void)viewDidLoad | |
{ | |
//... | |
_textViewFrame = self.view.bounds; | |
//... | |
} | |
//update _textViewFrame variable when the keyboard is shown | |
#pragma mark - UITextView 델리게이트 메소드 | |
- (void)textViewDidBeginEditing:(UITextView *)textView | |
{ | |
//텍스트 뷰 사이즈 조정 | |
[UIView animateWithDuration:0.3 animations:^{ | |
_textViewFrame = self.view.bounds; | |
_textViewFrame.size.height -= 216.0f; //reduces the height of the on-screen keyboard | |
_textView.frame = _textViewFrame; | |
}]; | |
} | |
//return the text view frame to its original size when editing finishes | |
- (void)textViewDidEndEditing:(UITextView *)textView | |
{ | |
//copy the updated note text to the underlying model | |
self.note.contents = textView.text; | |
_textViewFrame = self.view.bounds; | |
_textView.frame = _textViewFrame; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment