質問

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 キーボードがランドスケープモードでオーバーラップする量だけプロパティがありますが、両方の方向にキーボードの高さをハードコーディングせずにそれを行う良い方法を見ることができません。

役に立ちましたか?

解決

私は誤ってこの他の何かをデバッグする答えを見つけました。 iPadがポートレートから風景に回転すると、ポーテイトキーボードがランドスケープキーボードが表示される直前に隠れている(および通知を送信する)ことがわかります(および送信します これは お知らせ)。ですから、あなたがそれを説明する限り、あなたは大丈夫です。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top