欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

APP開(kāi)發(fā)之IOSSWIFT如何隱藏鍵盤(pán)-IOS隱藏鍵盤(pán)全解

2023-02-22    分類: App開(kāi)發(fā)

如果你是剛從網(wǎng)站建設(shè)行業(yè)轉(zhuǎn)到APP開(kāi)發(fā),那么你會(huì)覺(jué)得不可思議,隱藏鍵盤(pán)這么簡(jiǎn)單的事情,還要這樣大費(fèi)周張。先不牢騷了,以上是創(chuàng)新互聯(lián)的解決經(jīng)驗(yàn):
正常情況下,只要觸摸焦點(diǎn)放在輸入框如textField\textView上,自動(dòng)會(huì)彈出鍵盤(pán),所以,隱藏鍵盤(pán)的最終方法就是讓控件失去焦點(diǎn)。textField.resignFirstResponder()
textView.resignFirstResponder()
用例一、TextField按Enter鍵隱藏實(shí)現(xiàn)委托UITextFieldDelegate 方法
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}用例二、點(diǎn)擊其他任意地方隱藏override func touchesBegan(touches: Set, withEvent event: UIEvent?) {
self.textField.resignFirstResponder()
self.textView.resignFirstResponder()
}
用例三、點(diǎn)擊手勢(shì)隱藏let tapGesture:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "hideKeyboard:")
self.view.addGestureRecognizer(tapGesture)
func hideKeyboard(sender: UITapGestureRecognizer) {
self.SearchBar1.resignFirstResponder()
}
用例四、滾動(dòng)tableView隱藏func scrollViewDidScroll(scrollView: UIScrollView) {
self.SearchBar1.resignFirstResponder()
}

用例五、通過(guò)鍵盤(pán)通知事件在其上方添加按鈕
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
//添加鍵盤(pán)彈出通知
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardDidShow:"), name: UIKeyboardDidShowNotification, object: nil)
//添加鍵盤(pán)收起同志
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)
}
override func viewDidDisappear(animated: Bool) {
//取消通知
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
func keyboardDidShow(notification:NSNotification) {
let keyBoardBounds = (notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
let deltaY = keyBoardBounds.size.height
let frame_height = self.view.frame.size.height
let butheight = frame_height - deltaY - 40
let width = self.view.frame.size.width
let cancalButton = UIButton(frame: CGRectMake(0,butheight,width/2,40))
cancalButton.setTitle("取消", forState:UIControlState.Normal)
cancalButton.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
cancalButton.backgroundColor = UIColor(red: 238/255, green: 238/255, blue: 238/255, alpha: 1)
cancalButton.addTarget(self, action: "hideKeyboard", forControlEvents: UIControlEvents.TouchUpInside)
cancalButton.tag = 9999991
self.view.addSubview(cancalButton)
let completEditButton = UIButton(frame: CGRectMake(width/2,butheight,width/2,40))
completEditButton.setTitle("完成", forState:UIControlState.Normal)
completEditButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
completEditButton.backgroundColor = UIColor.darkGrayColor()
completEditButton.addTarget(self, action: "completeKeyboard", forControlEvents: UIControlEvents.TouchUpInside)
completEditButton.tag = 9999992
self.view.addSubview(completEditButton)
}
func keyboardWillHide(notification:NSNotification) {
if self.view.viewWithTag(9999991) != nil {
let btnCancal = self.view.viewWithTag(9999991) as! UIButton
let btnComplete = self.view.viewWithTag(9999992) as! UIButton
btnCancal.removeFromSuperview()
btnComplete.removeFromSuperview()
}
}

網(wǎng)頁(yè)名稱:APP開(kāi)發(fā)之IOSSWIFT如何隱藏鍵盤(pán)-IOS隱藏鍵盤(pán)全解
本文鏈接:http://aaarwkj.com/news/239064.html

網(wǎng)站建設(shè)、網(wǎng)絡(luò)推廣公司-創(chuàng)新互聯(lián),是專注品牌與效果的網(wǎng)站制作,網(wǎng)絡(luò)營(yíng)銷seo公司;服務(wù)項(xiàng)目有App開(kāi)發(fā)

廣告

聲明:本網(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
国产精品久久久久大屁股精品性色| 欧美日韩亚洲中文字幕| 日韩一区二区三级在线| 欧美特黄在线免费观看| 国产熟女一区二区三区正在 | 免费看夫妻性生活视频| 在线免费观看视频97| 日本在线高清精品人妻| 中文字幕乱码高清免费| 手机黄色av免费在线网址| 国内熟妇人妻色在线三级| 国产精品99久久久久久宅男九| 日本在线观看免费高清| 国产精品亚洲二区三区| 国产精品久久久99| 日本精品一区二区三区免费| 国产丝袜美腿一二三区| 人妻少妇亚洲中文字幕| 国产av一区最新精品麻豆| 亚洲欧美日韩国产桃色| 欧美偷拍一区二区三区| 亚洲女同成人在线观看| 人人人妻人人澡人人爽e| 校园春色亚洲欧美日韩| 国产丝袜肉丝在线播放| 亚洲国产精品综合久久网络| av一区二区三区网站| 国产三级在线观看91| 欧美亚洲国产青草久久| 日本欧美二区在线看| 亚洲乱人伦一区二区三区| 亚洲综合另类小说专区| 少妇高潮时会抱紧男人脖子| 亚洲高清中文字幕专区| 天堂中文字幕在线乱码一区 | 久久精品国产亚洲av高清综合| 内射嫩国产欧美国产日韩欧美| 深夜释放自己污在线看| 人妻少妇一区二区三区四区| 国产精品粉嫩在线播放| 自拍偷拍亚洲丝袜大秀|