1

TPKeyboardAvodingScrollViewクラスを使用して、キーボードがUITextField. ただし、iPhone には奇妙なバグがいくつかありますUITextField。テキストフィールドをクリックすると、高すぎますが上がります。

ここに画像の説明を入力

GitHub リンクのノートには次のように書かれています。

ノート

これらのクラスは現在、contentInset パラメーターを調整して、コンテンツがキーボードの下に移動しないようにします。これは、フレームを調整するのではなく、安定する前にビューが上にジャンプするぎくしゃくしたアニメーションになる iOS のバグを回避するために行われます。この回避策を容易にするために、contentSize は少なくともビューのフレームと同じサイズに維持されます。

これと関係があるのか​​もしれませんが、どうすればこの問題を解決できるかわかりません。

私はすでにこの行を変更しようとしました:

[self setContentOffset:CGPointMake(self.contentOffset.x, 
                                   [self idealOffsetForView:firstResponder withSpace:[self keyboardRect].origin.y - self.bounds.origin.y])

あり(+100追加):

[self setContentOffset:CGPointMake(self.contentOffset.x, 
                                   [self idealOffsetForView:firstResponder withSpace:[self keyboardRect].origin.y - self.bounds.origin.y+100])

しかし、これは iPad では動作しないため、良い方法ではありません。

4

1 に答える 1

1

最近同じ問題がありました。私にとって、解決策は -(CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space メソッドを変更することでした。これが私のプロジェクトでどのように見えるかです:

-(CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space {

// Convert the rect to get the view's distance from the top of the scrollView.
CGRect rect = [view convertRect:view.bounds toView:self];

// Set starting offset to that point
CGFloat offset = rect.origin.y;


if ( view.bounds.size.height < space ) {
    // Center vertically if there's room
    offset -= floor((space-view.bounds.size.height)/2.0);
}
if ( offset + space > self.contentSize.height ) {
    // Clamp to content size
    offset = self.contentSize.height - space;
}

if (offset < 0) offset = 0;

return offset;
}

変更は、条件ブロックから最初のパスを削除することでした: if ( self.contentSize.height - offset < space ) と "else" パスだけを残します。

于 2013-04-23T14:11:31.493 に答える