UITextView setText不应该在ios8中跳转到顶部 [英] UITextView setText should not jump to top in ios8

查看:119
本文介绍了UITextView setText不应该在ios8中跳转到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跟随iOS 8代码每秒调用:

Following iOS 8 code is called every second:

- (void)appendString(NSString *)newString toTextView:(UITextView *)textView {
    textView.scrollEnabled = NO;
    textView.text = [NSString stringWithFormat:@"%@%@%@", textView.text, newString, @"\n"];
    textView.scrollEnabled = YES;
    [textView scrollRangeToVisible:NSMakeRange(textView.text.length, 0)];
}

目标是在XCode控制台时具有与XCode控制台相同的向下滚动行为文字从底部开始运行。不幸的是,在我使用scrollRangeToVisible再次向下滚动之前,setText会导致视图重置到顶部。

The goal is to have the same scrolling down behaviour as the XCode console when the text starts running off the bottom. Unfortunately, setText causes the view to reset to the top before I can scroll down again with scrollRangeToVisible.

这在iOS7中使用上面的代码解决了它并且有效,但之后上周升级到iOS8,该解决方案似乎不再适用。

This was solved in iOS7 with the above code and it worked, but after upgrading last week to iOS8, that solution no longer seems to work anymore.

我无法弄清楚如何在没有跳跃行为的情况下顺利运行?

I can't figure out how to get this going fluently without the jumping behaviour?

推荐答案

尝试将文本添加到UITextView(不使用scrollRangeToVisible / scrollEnabled)。在iOS8 SDK中不再需要使用滚动启用/禁用的黑客攻击。 UITextView会自动滚动。

Try just to add text to UITextView (without scrollRangeToVisible/scrollEnabled). It seams that hack with scroll enabled/disabled is no more needed in iOS8 SDK. UITextView scrolls automatically.

这篇关于UITextView setText不应该在ios8中跳转到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆