-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
- (void)textDidChange
{
self.placeholderView.hidden = self.text.length > 0;
NSInteger height = ceilf([self sizeThatFits:CGSizeMake(self.bounds.size.width, MAXFLOAT)].height);
if (_textH != height) {
self.scrollEnabled = height > _maxTextH && _maxTextH > 0;
if (self.scrollEnabled) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.layoutManager.allowsNonContiguousLayout = false;
self.contentSize = [self sizeThatFits:CGSizeMake(self.bounds.size.width, MAXFLOAT)];
[self setContentOffset:CGPointMake(0, self.contentSize.height - self.bounds.size.height) animated:NO];
CGFloat cursorPosition;
if (self.selectedTextRange) {
cursorPosition = [self caretRectForPosition:self.selectedTextRange.start].origin.y;
} else {
cursorPosition = 0;
}
float _minTextH = ceil(self.font.lineHeight * 1 + self.textContainerInset.top + self.textContainerInset.bottom);
CGRect cursorRowFrame = CGRectMake(0, cursorPosition - _minTextH, self.bounds.size.width, _minTextH);
CGRect textViewFrame = [self convertRect:cursorRowFrame fromView:self];
[self scrollRectToVisible:textViewFrame animated:NO];
[self layoutIfNeeded];
});
}
_textH = height;
if (_yz_textHeightChangeBlock && self.scrollEnabled == NO) {
_yz_textHeightChangeBlock(self.text,height);
[self.superview layoutIfNeeded];
self.placeholderView.frame = self.bounds;
}
}
}
Metadata
Metadata
Assignees
Labels
No labels