【问题标题】:Scroll bug using UITextView in iOS 8.1 (iPad 2)在 iOS 8.1 (iPad 2) 中使用 UITextView 滚动错误
【发布时间】:2015-02-03 15:47:43
【问题描述】:

我遇到的问题是:Smooth UITextView auto scroll to bottom of frame

基本上,当我在 UITextView 中将文本附加到现有文本时使用自动滚动功能时,滚动可以工作,但它总是先到顶部然后一直滚动到底部(这对于大文本来说是个问题,或者聊天室)

当我尝试这个人的解决方案时,它是:

textview.scrollEnabled= NO;
textview.text = [textview.text stringByAppendingString:createdString];
textview.scrollEnabled= YES;
[textview scrollRangeToVisible:textview.selectedRange];

所以,我发现了一个错误,似乎 'textview.scrollEnabled' 永远不会返回 YES,因此滚动将永远无法工作。

我要么有一个奇怪的滚动,它会回到顶部然后到底部,要么是另一个错误,即启用的滚动永远不会回到 YES。

【问题讨论】:

    标签: ios objective-c xcode uiscrollview uitextview


    【解决方案1】:

    这应该适合你。 摆脱textView.scrollEnabled = NO;

    所以你只剩下:

    textview.text = [textview.text stringByAppendingString:createdString];
    [textview scrollRangeToVisible:textview.selectedRange]
    

    并将其添加到您的 viewDidLoad:

    textview.layoutManager.allowsNonContiguousLayout = NO;
    

    【讨论】:

      【解决方案2】:

      我也遇到了类似的问题,滚动在 iOS 7 和 iOS 9 中运行良好,但在 iOS 8 中却不行。所以,我发现在 iOS 8 中滚动运行的解决方案是:

      NSString *strValue = [NSString stringWithFormat:@"Your text"];
      txtVwObj.text = strValue; // If in your case text needs to give before scroll disable.
      txtVwObj.scrollEnabled = NO;
      
      // and set whatever you need for UITextView properties. 
      // at last add the following code snippet.
       txtVwObj.scrollEnabled = YES;
       txtVwObj.text = @"";
       txtVwObj.text = [txtVwObj.text stringByAppendingString:strValue];
      

      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多