- (void)showLog:(NSString *)log {
if ([@"" isEqualToString:_logTxtV.text]) {
_logTxtV.text = [NSString stringWithFormat:@">>%@",log];
} else {
_logTxtV.text = [NSString stringWithFormat:@"%@\n>>%@",_logTxtV.text,log];
}
[_logTxtV scrollRangeToVisible:NSMakeRange(_logTxtV.text.length, 1)];
_logTxtV.layoutManager.allowsNonContiguousLayout = NO;
}
关键:
[_logTxtV scrollRangeToVisible:NSMakeRange(_logTxtV.text.length, 1)];
_logTxtV.layoutManager.allowsNonContiguousLayout = NO;每次添加新的内容,都会定位到最后一行
本文介绍了一个iOS应用中实现日志实时显示与自动滚动到最新内容的方法。通过简单的代码示例,展示了如何在每次添加新日志时确保视图自动滚动到底部,并禁用非连续布局以优化性能。
2159

被折叠的 条评论
为什么被折叠?



