7

私が 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、横向きモードでキーボードがオーバーラップする量だけプロパティの高さを調整するだけですが、両方の向きでキーボードの高さをハードコーディングしないと、それを行う良い方法がわかりません。したい。

4

1 に答える 1

16

私は偶然、このデバッグに対する答えを別の方法で見つけました。iPad が縦向きから横向きに回転すると、横向きキーボードが表示される (そして通知が送信される) 直前に縦向きキーボードが非表示になる (そして通知が送信される) ことが判明しまし。あなたがそれを説明している限り、あなたは大丈夫です。

于 2010-10-04T21:58:21.237 に答える