atmの下のコードを使用します。キーボードが起動している間にアプリを終了しない限り(ホームを押す)、正常に動作しています。だから私は単純に、viewWillDissappear:(BOOL)animatedでresignFirstResponderだけだと思ったが、どうやらホームを押すとは呼ばれない...
問題のシナリオの簡単な要約: textView をタップ -> キーボードが表示され、ビューがシフト ホームを押す アプリをもう一度開く -> キーボードがまだ表示されている、ビューが元の場所に戻ったため、コンテンツが表示されない
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void) keyboardWillShow: (NSNotification*) aNotification;
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = [[self view] frame];
rect.origin.y -= 60;
[[self view] setFrame: rect];
[UIView commitAnimations];
}
- (void) keyboardWillHide: (NSNotification*) aNotification;
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = [[self view] frame];
rect.origin.y += 60;
[[self view] setFrame: rect];
[UIView commitAnimations];
}