2
This commit is contained in:
@@ -56,6 +56,9 @@
|
||||
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
_scrollView.alwaysBounceVertical = YES;
|
||||
_scrollView.showsVerticalScrollIndicator = YES;
|
||||
// 留一点底部余量,避免最后一行视觉上“贴底被遮住”的感觉
|
||||
_scrollView.contentInset = UIEdgeInsetsMake(0, 0, 6, 0);
|
||||
_scrollView.scrollIndicatorInsets = _scrollView.contentInset;
|
||||
[self addSubview:_scrollView];
|
||||
}
|
||||
|
||||
@@ -171,7 +174,6 @@
|
||||
label.textColor = self.labelTextColor;
|
||||
label.userInteractionEnabled = YES;
|
||||
label.text = @"";
|
||||
label.backgroundColor = [UIColor redColor];
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleLabelTap:)];
|
||||
[label addGestureRecognizer:tap];
|
||||
|
||||
@@ -196,8 +198,10 @@
|
||||
NSString *trimmed = [current.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
current.text = trimmed;
|
||||
self.buffer = trimmed;
|
||||
[self layoutLabelsForCurrentWidth];
|
||||
}
|
||||
// 无论是否裁剪,都重新布局并滚动到底部,避免最后一段显示不全
|
||||
[self layoutLabelsForCurrentWidth];
|
||||
[self scrollToBottomIfNeeded];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
@@ -247,7 +251,8 @@
|
||||
CGFloat contentHeight = self.scrollView.contentSize.height;
|
||||
if (contentHeight > height && height > 0) {
|
||||
CGPoint bottomOffset = CGPointMake(0, contentHeight - height);
|
||||
[self.scrollView setContentOffset:bottomOffset animated:YES];
|
||||
// 使用无动画滚动,避免在短时间内多次追加时“最后一行没完全跟上”的错觉
|
||||
[self.scrollView setContentOffset:bottomOffset animated:NO];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user