Last active
December 21, 2015 22:39
-
-
Save xandrucea/6376993 to your computer and use it in GitHub Desktop.
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
!!!!!! | |
On every user input the methods "textViewDidChange", "resizeTextViewHeight" and "textView:shouldChangeTextInRange" will be called | |
!!!!!! | |
hide keyboard when pressing return button | |
----------------------------------------- | |
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { | |
if([text isEqualToString:@"\n"]) { | |
[textView resignFirstResponder]; | |
return NO; | |
} | |
return YES; | |
} | |
method that will be called for each keyboard press | |
-------------------------------------------------- | |
- (void)textViewDidChange:(UITextView *)textView; | |
center text vertically inside a textview | |
---------------------------------------- | |
[self.textViewDescription addObserver:self | |
forKeyPath:@"contentSize" | |
options:(NSKeyValueObservingOptionNew) | |
context:NULL]; | |
[super viewDidLoad]; | |
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
UITextView *tv = object; | |
CGFloat topCorrect = ([tv bounds].size.height - [tv contentSize].height * [tv zoomScale])/2.0; | |
topCorrect = ( topCorrect < 0.0 ? 0.0 : topCorrect ); | |
tv.contentOffset = (CGPoint){.x = 0, .y = -topCorrect}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment