4

複数のビューを持つスクロールビューがあります。これらすべてのビューにはテキスト フィールドがあり、クリックするとキーボードがポップアップします。場合によっては、キーボードがこのサブビューを非表示にすることがあります。これを事前に計算できるかどうかを判断したいと思います。はいの場合、どうすればできますか..?scrollRectToVisibleここで ofUIScrollViewメソッドを任意の用途に使用できますか? さらに明確にするために、添付の画像をご覧ください。アイデアをありがとう..

編集: これらのサブビューは動的に描画されるため、これを特定してハードコードすることはできません。

ここに画像の説明を入力

4

3 に答える 3

4

ランドスケープ モードの場合:

iPad の高さ: 768 ピクセル。

キーボードの高さ: 352 ピクセル。

つまり、キーボードの x 座標: 0.0 および y 座標: 416

コントロールのy座標が416より大きいときはいつでも。キーボードがポップアップすると非表示になることを理解してください。

于 2013-02-28T10:05:57.747 に答える
1

ええ、サブビューを少し上にシフトして表示できるようにする必要があります。このアニメーションを使用して、サブビューを任意のポイントにシフトできます。レイヤーと宛先ポイントを渡すだけです。ユーザーがキーボードのReturnキーを押したら、もう一度前のポイントに移動します:)

-(void)moveLayer:(CALayer*)layer to:(CGPoint)point
{
    // Prepare the animation from the current position to the new position
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue = [layer valueForKey:@"position"];
    animation.duration = 0.2;

    animation.toValue = [NSValue valueWithCGPoint:point];

    // Update the layer's position so that the layer doesn't snap back when the animation completes.
    layer.position = point;

    // Add the animation, overriding the implicit animation.
    [layer addAnimation:animation forKey:@"position"];
}
于 2013-02-28T10:09:37.927 に答える
1

次の通知に登録します。

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidChangeFrame:)
                                                 name:UIKeyboardDidChangeFrameNotification
                                               object:nil];

これを処理するようにしてください:

- (void)keyboardDidChangeFrame:(NSNotification *)notification
{
    CGRect keyboardEndFrame;
    [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame fromView:nil];

    // Add your code to check if the keyboard is hiding your views.
    // CGRectIntersectsRect should help you here.
    // For each view you are worried about hiding, run CGRectIntersectsRect to check
    // if an intersection occurs. If it does, then you can
    // move your view using UIScrollView's setContentOffset: animated: method.

}
于 2013-02-28T10:38:52.127 に答える