0

UITextViewキーボードが開いているときにサイズを変更しようとしています。

私の新しいサイズを与えるためにUITextView(キーボードによって影にならないように)、次の計算を行います

firstResult = UITextView bottom coordinate - keyboard top coordinate

firstResult影のサイズを持つ必要がありますUITextView frame

次にtextView.frame.size.height -= firstResult、キーボードによって影にならない新しいサイズにする必要があります。

際立っているコードの問題は、キーボードの後ろに隠されている UIView の一部が常に存在することです。

新しいサイズが常に正しいように、誰かが私の計算の何が問題なのか指摘できますか? または、オンラインで見つけたすべての例が何らかの形で機能しないため、適切に UITextView のサイズを変更するために使用できるその他の方法。

コード

- (void)keyboardWasShown:(NSNotification *)notification {
CGRect viewFrame = input.frame;
    CGFloat textEndCord = CGRectGetMaxY(input.frame);
    CGFloat kbStartCord = input.frame.size.height - ([[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]).size.height;

    CGFloat result = fabsf( input.frame.size.height - fabsf( textEndCord - kbStartCord ));
    viewFrame.size.height -= result;
    NSLog(@"Original Height:%f, TextView End Cord: %f, KB Start Cord: %f, resutl: %f, the sum: %f",input.frame.size.height, textEndCord,kbStartCord,result,fabsf( textEndCord - kbStartCord ));
    input.frame = viewFrame;
}

4

1 に答える 1