これが何が起こっているかのスクリーンショットです。
緑の背景は、スクロールビューのビューです(つまり、「コンテンツサイズ」と「コンテンツオフセット」をマークします)。
オレンジはスクロールビューフレームです。
キーボードが上がっています...スクロールビューでコンテンツがうまくスクロールされました。
テキストフィールドをクリックすると、キーボードが非表示になります
スクロールビュー(オレンジ)は適切な高さのように見えますが、コンテンツは約100px(緑)にジャンプしています。
何がこれを引き起こしているのかわかりません-それがiOSのバグなのか、それとも何なのか(私のデバイスでも起こります)。
これは、キーボードが表示/非表示になるタイミングに基づいてビューのサイズを変更するコードです。
- (void)keyboardWillShow:(NSNotification *)notif {
[self.mainScrollView setAutoresizesSubviews:NO];
// get the scroll view frame size
CGRect frame = [self.mainScrollView frame];
frame.size.height = self.view.frame.size.height-216;
[UIView beginAnimations:@"scrollViewAnimations" context:nil];
[UIView setAnimationDuration:0.3];
[self.mainScrollView setFrame:frame];
[UIView commitAnimations];
// add tap gesture recognizer
_tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_dismissKeyboard:)];
[_tap setDelegate:self];
[self.view addGestureRecognizer:_tap];
}
- (void)keyboardWillHide:(NSNotification *)notif {
CGRect frame = [self.mainScrollView frame];
frame.size.height = self.view.frame.size.height;
[UIView beginAnimations:@"scrollViewAnimations" context:nil];
[UIView setAnimationDuration:0.3];
[self.mainScrollView setFrame:frame];
[UIView commitAnimations];
[self.view removeGestureRecognizer:_tap];
}
どんな助けやガイダンスも素晴らしいでしょう、ありがとう!なぜこれをしているのですか?それはバグですか?それは私のコードのどこかに埋もれているものですか?もしそうなら、私はそれを見つけることができません。これは、ビューアニメーションの実行方法のエラーですか?