我试图在键盘打开时调整UITextView
的大小。当键盘打开时,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;
}
在您的NSLog显示的结果的预期? – CoderPug
Nop,我的方程式中缺少一些东西,因为我从来没有得到正确的尺寸 –