Help us understand the problem. What is going on with this article?

iOS7.0でUITextViewのカーソルがキーボードの下に隠れる問題を解決する方法

More than 5 years have passed since last update.

iOS7.0ではXcode5でビルドするとUITextViewのカーソルがキーボードの下に隠れる場合があります。
この問題を解決する方法を発見しました。タイミング依存なのがなんですが、UITextViewのサブクラスを作る必要がないのが良いところです。
iOS7.1で何もしなくても解決されることを望みます。

ObjectiveC
@interface ViewController : UIViewController <UITextViewDelegate>
@end

@implementation ViewController
-(void) scrollToVisible:(UITextView *)textView
{
    if ([textView isFirstResponder] && textView.selectedTextRange.end) {
        CGRect caretRect = [textView caretRectForPosition:textView.selectedTextRange.end];
        [textView scrollRectToVisible:caretRect animated:YES];
    }
}

-(void) textViewDidBeginEditing:(UITextView *)textView
{
    [self performSelector:@selector(scrollToVisible:) withObject:textView afterDelay:0.3];
}

- (void) textViewDidChangeSelection:(UITextView *)textView
{
    [self performSelector:@selector(scrollToVisible:) withObject:textView afterDelay:0.1];
}

-(void) textViewDidChange:(UITextView *)textView
{
    [self performSelector:@selector(scrollToVisible:) withObject:textView afterDelay:0.2];
}
@end
T_Fuchi
iPhoneアプリ作ります。代表作はArrow Noteです。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away