gpt4 book ai didi

iphone - 显示 iPhone 键盘时调整 UIView 大小,如何操作?

转载 作者:行者123 更新时间:2023-12-03 20:23:31 25 4
gpt4 key购买 nike

我将向您展示一个众所周知的 Whatsapp 的示例当您触摸文本内部时,键盘会弹出,因此我必须向上移动或移动所有栏并将 View 大小调整为一半,这样我仍然可以看到我正在输入的文本和发送按钮

第一阶段: http://www.appbank.net/wp-content/uploads/2010/10/WhatsAppMessenger-18.jpg

第二阶段: http://www.onetooneglobal.com/wp-content/uploads/2011/02/onetoone_whatsapp_2.png

实现这一目标的最佳方法是什么?

最佳答案



#define kOFFSET_FOR_KEYBOARD 280.0

- (void)keyboardWillHide:(NSNotification *)notif {
[self setViewMoveUp:NO];
}


- (void)keyboardWillShow:(NSNotification *)notif{
[self setViewMoveUp:YES];
}


- (void)textFieldDidBeginEditing:(UITextField *)textField {
stayup = YES;
[self setViewMoveUp:YES];
}


- (void)textFieldDidEndEditing:(UITextField *)textField {
stayup = NO;
[self setViewMoveUp:NO];
}

//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMoveUp:(BOOL)moveUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];

CGRect rect = self.view.frame;
if (moveUp)
{
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.

if (rect.origin.y == 0 ) {
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
//rect.size.height += kOFFSET_FOR_KEYBOARD;
}

}
else
{
if (stayup == NO) {
rect.origin.y += kOFFSET_FOR_KEYBOARD;
//rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
}
self.view.frame = rect;
[UIView commitAnimations];
}

试试这个方法。根据您的要求进行编辑。

关于iphone - 显示 iPhone 键盘时调整 UIView 大小,如何操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5408848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com