iOS7でUITextView内に入力するときに行間隔/段落間隔を達成する方法を理解するのに役立つこの素晴らしい例に出くわしましたが、問題があり、まだ学習しているので、誰かが問題を解決するのを手伝ってくれることを願っていますTextKitについてお願いします。
これは実際の例です https://github.com/downie/DoubleSpacedTextView
2 つのファイルを添付しました:-
1- これは問題のビデオです:- http://1drv.ms/1o8Rpd2
2- これは私がテストしているプロジェクトです: http://1drv.ms/1o8RtK0
問題は、テキスト行の間に空白行 (少なくとも 2 行の空白行) があり、空白行の内側をクリックして UITextView をアクティブにし、キーボードを表示すると、テキストが上に移動するか、書式設定が失われることです。
これは私がオリジナルから少し変更したコア関数であり、書式設定を行います。完全に機能しますが、UITextView 内を初めてクリックしたときは機能しません:-
- (void) formatText
{
__block CGFloat topOffset = 0;
NSRange lineGlyphRange = [self.layoutManager glyphRangeForTextContainer:self.textContainer];
[self.layoutManager
enumerateLineFragmentsForGlyphRange:lineGlyphRange usingBlock:^(CGRect rect, CGRect usedRect, NSTextContainer *textContainer, NSRange glyphRange, BOOL *stop)
{
CGRect adjustedRect = rect;
CGRect adjustedUsedRect = usedRect;
adjustedRect.origin.y = topOffset;
adjustedUsedRect.origin.y = topOffset;
[self.layoutManager setLineFragmentRect:adjustedRect forGlyphRange:glyphRange usedRect:adjustedUsedRect];
topOffset += 30; // 30 is the space between the lines you can adjust this as you like
}];
CGRect adjustedExtraLineFragmentRect = self.layoutManager.extraLineFragmentRect;
CGRect adjustedExtraLineFragmentUsedRect = self.layoutManager.extraLineFragmentUsedRect;
adjustedExtraLineFragmentRect.origin.y = topOffset;
adjustedExtraLineFragmentUsedRect.origin.y = topOffset;
[self.layoutManager setExtraLineFragmentRect:adjustedExtraLineFragmentRect usedRect:adjustedExtraLineFragmentUsedRect textContainer:self.textContainer];
}
これを止めることができるかどうか見ていただけますか?UITextView に入力するときにテキストが常にフォーマットされるようにします。
TextKit または属性付きテキストを使用して、書式設定されたテキスト (行間隔付き) を UITextView に入力する方法を示す他の例はありますか?
iOS6以降、この問題に苦労しています。
ありがとう、
意思