iOS7 UITextView 游標問題,ios7uitextview
最近在項目中遇到UITextView在ios7上出現編輯進入最後一行時游標消失,看不到最後一行,變成盲打,stackOverFlow網站上有大神指出,是ios7本身bug,加上下面一段代碼即可:
1 -(void)textViewDidChange:(UITextView *)textView { 2 CGRect line = [textView caretRectForPosition: 3 textView.selectedTextRange.start]; 4 CGFloat overflow = line.origin.y + line.size.height 5 - ( textView.contentOffset.y + textView.bounds.size.height 6 - textView.contentInset.bottom - textView.contentInset.top ); 7 if ( overflow > 0 ) { 8 // We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it) 9 // Scroll caret to visible area10 CGPoint offset = textView.contentOffset;11 offset.y += overflow + 7; // leave 7 pixels margin12 // Cannot animate with setContentOffset:animated: or caret will not appear13 [UIView animateWithDuration:.2 animations:^{14 [textView setContentOffset:offset];15 }];16 }17 }