UITextView漢字光標問題

有可能是系統的bug,iOS9下面是沒有該問題的。就是輸入漢字,位置出錯,被擋住。經過Google解決辦法有兩個:
1,self.textview.layoutManager.allowsNonContiguousLayout = NO;

2,
- (void)textViewDidChangeSelection:(UITextView *)textView {
[textView scrollRangeToVisible:textView.selectedRange];
}

還有部分指的是下面一個函數,暫未實驗,先放在這裏。
- (void)textViewDidChange:(UITextView *)textView {
CGRect line = [textView caretRectForPosition:
textView.selectedTextRange.start];
CGFloat overflow = line.origin.y + line.size.height -
(textView.contentOffset.y +
textView.bounds.size.height -
textView.contentInset.bottom -
textView.contentInset.top );
if ( overflow > 0 )
{
// We are at the bottom of the visible text and introduced
// a line feed, scroll down (iOS 7 does not do it)
// Scroll caret to visible area
CGPoint offset = textView.contentOffset;
offset.y += overflow + 7; // leave 7 pixels margin
// Cannot animate with setContentOffset:animated:
// or caret will not appear
[UIView animateWithDuration:.2 animations:^{
[textView setContentOffset:offset];
}];
}
}

文章鏈接:
http://www.4byte.cn/question/198472/uitextview-scrolling-up-after-deleting-inserting-text.html
http://petersteinberger.com/blog/2014/fixing-uitextview-on-ios-7/
http://stackoverflow.com/questions/19259886/uitextview-cursor-not-positioning-properly-when-editing-in-ios-7-why
http://justabunchoftyping.com/fix-for-ios7-uitextview-issues

發佈了26 篇原創文章 · 獲贊 1 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章