4

いくつかの属性を適用するために、レンダリングする前に、入力されたテキストをキャプチャする必要があります。

そのために、NSAttributedString と共に UITextView のデリゲート メソッド shouldChangeTextInRange を使用しています。これまでのところ、うまく機能しています。

問題は、UITextView が一定量のテキストを取得してスクロールを開始したときに、attributedText を変更すると一番上までスクロールし、次の char を使用すると最後までスクロールすることです。

タイピングしている間、そのダンスが上下に動き続けます..

属性付きテキストの代わりに textview.text を設定すると、動作します n

なにか提案を?

前もって感謝します。

- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{

    NSAttributedString * newString = [[NSAttributedString alloc] initWithString:text attributes:nil];
    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithAttributedString:_textView.attributedText];

    [string insertAttributedString:newString atIndex:range.location];

    textView.attributedText = string;

    range.location += text.length;

    textView.selectedRange = range;

    return NO;
}
4

2 に答える 2

0

あなたの のポイントについてはわかりませんshouldChangeTextInRangeが、望ましくない自動スクロールを修正するには、 の設定を で囲んでみてtextView.attributedTextください[textView setScrollEnabled:NO]

あれは:

[textView setScrollEnabled:NO];
textView.attributedText = string;
range.location += text.length;
[textView setScrollEnabled:YES];
于 2013-03-20T21:14:27.107 に答える
0
textView.layoutManager.allowsNonContiguousLayout = NO;

次に、attributedText を変更しても、一番上までスクロールしません。わたしにはできる。

于 2017-04-07T05:03:44.560 に答える