For this to work, by observing the changes to the contentSize property and then setting the contentOffset.
- (void)viewDidLoad{
[super viewDidLoad];
[myTextView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:nil];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
UITextView *myView = object;
CGFloat offSet = ([myView bounds].size.height - [myView contentSize].height * [myView zoomScale])/2.0;
offSet = offSet < 0.0 ? 0.0 : offSet;
[myView setContentOffset:CGPointMake(0, -offSet) animated:NO];
}
source
share