私が iPad 用に設計しているアプリの場合、いくつかのテキスト フィールド/テキスト ビューを含むスクロール ビューがあります。すべてを表示し続けるためにcontentSize
、スクロール ビューのプロパティを調整して、キーボードがスクロール ビューに重なる量に対応するバッファーを下部に追加します。コードは次のとおりです (ここにはアプリ固有のものがありますが、理解できないほど多くないことを願っています)。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:nil object:nil];
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve curve;
[animationCurve getValue:&curve];
NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration;
[animationDuration getValue:&duration];
NSValue *endingFrame = [[aNotification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey];
CGRect frame;
[endingFrame getValue:&frame];
[UIView beginAnimations:@"keyboardWillShow" context:bodyView];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration:duration];
// Re-draw code here.
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)aNotification
{
NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve curve;
[animationCurve getValue:&curve];
NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration;
[animationDuration getValue:&duration];
[UIView beginAnimations:@"keyboardWillHide" context:bodyView];
[UIView setAnimationCurve:curve];
[UIView setAnimationDuration:duration];
// Re-draw code here
[UIView commitAnimations];
}
私の質問は次のとおりです。ローテーション中のキーボードのサイズはどうすればよいですか? iPad を回転させてもキーボードの通知はありませんが、キーボードのサイズが大幅に変わります。理想的にはcontentSize
、横向きモードでキーボードがオーバーラップする量だけプロパティの高さを調整するだけですが、両方の向きでキーボードの高さをハードコーディングしないと、それを行う良い方法がわかりません。したい。