一、問題描述

成都創(chuàng)新互聯(lián)專注于企業(yè)營(yíng)銷型網(wǎng)站、網(wǎng)站重做改版、薩迦網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為薩迦等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
?? 對(duì)于 ios 系統(tǒng),輸入框輸入內(nèi)容,軟鍵盤彈出,頁面內(nèi)容整體上移,但是軟鍵盤收起,頁面內(nèi)容不會(huì)自動(dòng)回到原本的位置,必須手動(dòng)下拉才會(huì)恢復(fù)
?? 剛開始遇到的時(shí)候,心想真是什么鬼畜問題都有,這邊直接給出解決辦法了
二、解決方式
首先在你們函數(shù)工具文件中加上下面的函數(shù)
在具體的文件中使用方式如下:
checkValue() 函數(shù)
至此, 關(guān)于 ios 軟鍵盤整出的雞肋問題就解決啦
現(xiàn)象描述:
ios平臺(tái),app內(nèi)嵌h5,當(dāng)軟鍵盤彈出再收起時(shí),頁面布局是錯(cuò)亂的。直接表現(xiàn)是當(dāng)點(diǎn)擊其他元素時(shí),卻導(dǎo)致了某個(gè)文本框聚焦。
解決方案:文本框focus(聚焦)時(shí)軟鍵盤彈出,blur(失焦)時(shí)軟鍵盤收起。可監(jiān)聽文本框失焦得知軟鍵盤收起,在文本框失焦時(shí)將頁面滾動(dòng)距離置為0,即可解決這一問題:
UITextField
*textfield常用的取消鍵盤方法.1、在textfield所在的控制器中,實(shí)現(xiàn)UITextFieldDelegate的方法。textfield.delegate
=
self;-
(BOOL)textFieldShouldReturn:(UITextField
*)textField{
[textfield
resignFirstResponder];
return
YES;}這樣,在點(diǎn)擊鍵盤的return鍵時(shí),就會(huì)退出鍵盤。[textfield
resignFirstResponder];表示textfield放棄第一響應(yīng)者,鍵盤自然就退出了。2、假設(shè)有UIView
*someView
是textfield的父視圖(不管中間是否還包含其他層的父視圖),那么,只要設(shè)置[someView
endEditting:YES];那么,所有在someView上的textfield,或者textView都會(huì)結(jié)束編輯,鍵盤也會(huì)自動(dòng)退出。以上就是常用的兩種退出鍵盤方法。IOS軟件開發(fā),UITextField怎么取消彈出系統(tǒng)鍵盤?
監(jiān)聽當(dāng)鍵盤將要出現(xiàn)時(shí)
OC版
[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification object:nil];
- ( void )keyboardWillShow:(NSNotification *)notification
{
//? ? //獲取鍵盤的高度
//? ? NSDictionary *userInfo = [notification userInfo];
//? ? NSValue *value = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
//? ? CGRect keyboardRect = [value CGRectValue];
//? ? int height = keyboardRect.size.height;
CGFloatcurkeyBoardHeight = [[[notificationuserInfo]objectForKey:@"UIKeyboardBoundsUserInfoKey"]CGRectValue].size.height;
? ? ? CGRectbegin = [[[notificationuserInfo]objectForKey:@"UIKeyboardFrameBeginUserInfoKey"]CGRectValue];
? ? ? CGRectend = [[[notificationuserInfo]objectForKey:@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
? ? // 第三方鍵盤回調(diào)三次問題,監(jiān)聽僅執(zhí)行最后一次
? ? if (begin.size.height0 (begin.origin.y-end.origin.y0)){
? ? ? CGFloatkeyBoardHeight = curkeyBoardHeight;
? ? ? NSLog(@"第三次:%f",keyBoardHeight);
? ? ? ? [UIView? animateWithDuration:0.05 animations:^{
? ? ? ? ? self .countLb_bottomH.constant= keyBoardHeight+10*sizeScale;
? ? ? }];
? ? }
}
- ( void )keyboardWillHide:(NSNotification*)notificationswift版
{
//獲取鍵盤的高度
NSDictionary*userInfo = [notificationuserInfo];
NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRectkeyboardRect = [valueCGRectValue];
int height = keyboardRect.size.height;
self .countLb_bottomH.constant = 12*sizeScale;
}
NotificationCenter.default.addObserver(self,selector:#selector(keyBoardShow(noty:)),name:Notification.Name.UIKeyboardWillShow,object:nil)
NotificationCenter.default.addObserver(self,selector:#selector(keyBoardHidden(noty:)),name:Notification.Name.UIKeyboardWillHide,object:nil)
@objcfunckeyBoardShow(noty:Notification){guardletuserInfo=noty.userInfoelse{return}letvalue=userInfo["UIKeyboardFrameBeginUserInfoKey"]as!NSValueletkeyboardRect=value.cgRectValueletkeyboradHeight=keyboardRect.size.height}
@objcfunckeyBoardShow(noty:Notification){guardletuserInfo=noty.userInfoelse{return}letvalue=userInfo["UIKeyboardFrameEndUserInfoKey"]as!NSValueletkeyboardRect=value.cgRectValueletkeyboradHeight=keyboardRect.size.height}
參考:
標(biāo)題名稱:ios開發(fā)鍵盤彈出,ios鍵盤沒反應(yīng)
轉(zhuǎn)載來源:http://chinadenli.net/article15/dsespgi.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、靜態(tài)網(wǎng)站、域名注冊(cè)、小程序開發(fā)、服務(wù)器托管、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)