0

なぜこれが起こっているのかわかりません..

ユーザーがテキスト フィールドに入力を開始したときにビューをアニメーション化しようとしています。しかし、コードは横向きの左向きでのみ機能し、横向きの右向きでは機能しません...

これらのメソッドは両方の方向で呼び出されます...

ここにコードがあります..

- (void)keyboardWasShown:(NSNotification *)aNotification {
    if ( keyboardShown )
        return;

        NSTimeInterval animationDuration = 0.3;
        CGRect frame = self.view.frame;
        frame.size.width += 150;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        self.view.frame = frame;
        [UIView commitAnimations];



    keyboardShown = YES;
}

- (void)keyboardWasHidden:(NSNotification *)aNotification {

        NSTimeInterval animationDuration = 0.3;
        CGRect frame = self.view.frame;
        frame.size.width -= 150;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        self.view.frame = frame;
        [UIView commitAnimations];


    keyboardShown = NO;
}

今のところ、値をハードコーディングしました..

4

2 に答える 2

1

サイズではなく、ビューの原点をアニメートしてみませんか?

frame.origin.y -= 150;

frame.origin.y = 0;
于 2012-06-21T05:10:20.883 に答える
0

OK..助けを借りてそれを理解しました...

ビューのフレームを設定し、そのコントローラーがウィンドウのルートビューコントローラーに追加される場合は、境界を使用する必要があります。

Windowsフレームは一定のままなので...

これが新しいコードの外観です。

- (void)keyboardShown:(NSNotification *) aNotification {
    if ( keyboardShown )
        return;
    CGRect frame = self.view.bounds;
    frame.origin.y += 150;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:0.3];
    self.view.bounds = frame;
    [UIView commitAnimations];
    keyboardShown = NO;
}

- (void)keyboardHidden:(NSNotification *) aNotification {
    CGRect frame = self.view.bounds;
    frame.origin.y -= 150;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:0.3];
    self.view.bounds = frame;
    [UIView commitAnimations];
    keyboardShown = NO;
}
于 2012-06-21T07:33:18.260 に答える