修改某个UITextField的键盘的返回键类型以及监听键盘的高度变化,取到键盘动画退出弹出的时间,一起随着键盘顶出来或者压下去,

1、修改某个UITextField的键盘的返回键类型:

[_bottomTextView setReturnKeyType:UIReturnKeyDone];

1.1、textFied点击return键之后有处理方法:

UITextViewDelegate里面有这样一个代理函数:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)tex

 1.2、textView点击return键之后的处理:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return

//在这里做你响应return键的代码

[self.rejectReasonTextView resignFirstResponder];

return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行

}

return YES;

}

~~~~~~~~~~~~~~~~~~~~~

以及监听键盘的高度变化,一起随着键盘顶出来或者压下去:

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHeightChange:) name:UIKeyboardWillChangeFrameNotification object:nil];

keyboardHeightChange:

-(void)keyboardHeightChange:(NSNotification *)notifi

{

self.dropButton.hidden = YES;

NSDictionary *dict=[notifi userInfo];

CGRect keyBoardRect=[[dict objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

CGFloat keyBoardHeight=keyBoardRect.size.height;

CGFloat keyBoardY=keyBoardRect.origin.y;

float animationDuration = [[dict objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];//取到键盘动画退出弹出的时间,好处,不同的键盘时间可能不一样

[UIView animateWithDuration:animationDuration animations:^{

CGRect bottomNewFrame=CGRectMake(_bottomView.frame.origin.x, keyBoardY+_bottomView.frame.size.height, _bottomView.frame.size.width, _bottomView.frame.size.height);

_bottomView.frame=bottomNewFrame;

}];

上一篇:微信小程序框架探究和解析


下一篇:js如何模拟multipart/form-data类型的请求