iOS系统键盘
iOS系统键盘在开发中可能遇到的问题: 1、选择键盘格式,比如数字键盘、邮箱键盘等 2、获取键盘高度,弹出键盘和推出键盘的监控 3、键盘自定义 这是开发中常见的几种问题,如有其他的可私聊共同学习,那首先我先说说我在开发中遇到这几种问题的解决办法 第一种: UITextView *textView; textView.keyboardType=UIKeyboardTypeDefault; // UIKeyboardTypeDefault UIKeyboardTypeASCIICapable == UIKeyboardTypeAlphabet UIKeyboardTypeNumbersAndPunctuation
UIKeyboardTypeURL UIKeyboardTypeNumberPad UIKeyboardTypeDecimalPad UIKeyboardTypePhonePad UIKeyboardTypeNamePhonePad UIKeyboardTypeEmailAddress UIKeyboardTypeTwitter UIKeyboardTypeWebSearch
键盘高度获取的监控方法 //键盘弹起 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
-(void)keyboardDidShow:(NSNotification *)notification { NSValue *value = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]; int height = [value CGRectValue].size.height; }
//键盘隐藏 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardDidHide) name:UIKeyboardWillHideNotification object:nil];
-(void)keyboardDidHide { [UIView animateWithDuration:0.3 animations:^{ self->_textView.frame=CGRectMake(W(15), H(65), ScreenWidth-W(30), HightNoNav-H(65)-H(100)); self->_bottomView.frame=CGRectMake(0, HightNoNav-H(100), ScreenWidth, H(100)); }]; } /注意/ 这里有一个地方要注意哦,UIKeyboardWillShowNotification 和UIKeyboardDidShowNotification都是弹出键盘,但是前面一个更好,因为如果你需要修改view的frame的话,用后面一个有延迟,不同步的修改让界面不是很好看
键盘自定义就是自定义UITextField或者UITextView的inputView。核心代码: -(void)btnAction { if(type==1) {//自定义键盘 _textView.inputView=_defineView; [_textView reloadInputViews]; } else {//默认系统键盘 _textView.inputView=nil; [_textView reloadInputViews]; } }
说到这里,小哥再说一个开发中遇到的问题,就是web调起来的键盘不能自定义inputView,为啥子,因为web的inputView是只读属性,所以没得选择,iOS和安卓都一样,这里如果碰到了,还是另想他法,如果您有好的处理办法,私聊我,不胜感激
|