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

APP開發(fā)之IOSSWIFT如何隱藏鍵盤-IOS隱藏鍵盤全解

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

如果你是剛從網(wǎng)站建設(shè)行業(yè)轉(zhuǎn)到APP開發(fā),那么你會(huì)覺得不可思議,隱藏鍵盤這么簡(jiǎn)單的事情,還要這樣大費(fèi)周張。先不牢騷了,以上是創(chuàng)新互聯(lián)的解決經(jīng)驗(yàn):
正常情況下,只要觸摸焦點(diǎn)放在輸入框如textField\textView上,自動(dòng)會(huì)彈出鍵盤,所以,隱藏鍵盤的最終方法就是讓控件失去焦點(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<UITouch>, 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ò)鍵盤通知事件在其上方添加按鈕
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
//添加鍵盤彈出通知
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardDidShow:"), name: UIKeyboardDidShowNotification, object: nil)
//添加鍵盤收起同志
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()
}
}

當(dāng)前標(biāo)題:APP開發(fā)之IOSSWIFT如何隱藏鍵盤-IOS隱藏鍵盤全解
路徑分享:http://aaarwkj.com/news14/239064.html

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

綿陽(yáng)服務(wù)器托管
免费的一区二区中文字幕| 国产成人91精品免费看片| 最美是你免费视频观看| 日韩精品一二三黄色一级| 亚洲欧美日韩不卡一区二区| 成人黄色av大片在线观看| 久久91亚洲精品中文字幕| 国产91九色在线播放| 国产,欧美,日韩,日日骚| 婷婷91麻豆精品国产人妻| 黄色午夜福利在线观看| 99精品久久久中文字幕日本| 日本熟妇中文字幕三级久久| 成人黄性视频免费网看| 亚洲精品一区二区三区网站| 亚洲精品综合在线二区| 日本人妻精品一区二区| 国产精品自拍国产精品| 国产亚洲精品久久久9| 久久九九精品日本人妻视频| 精品不卡一区二区三区| 国产精品日本在线观看| 尤物视频网站在线观看| 亚洲男女尻逼片视频网站| 欧美日韩亚洲人人夜夜澡| 国产在线一区二区三区蜜桃| 欧美制服丝袜亚洲自拍偷拍| 加勒比东京热视频在线| 国产91白丝在线观看| 亚洲欧美一区日韩尤物| 欧美日韩一区二区综合性色| 秒播视频午夜福利在线观看| 日韩欧美啪啪一区二区| 国产精品一区二区国产激情久久| 日本免费精品人成视频| 手机在线观看午夜小视频| 欧美伊香蕉久久综合网99| 四虎最新永久在线网站| 亚洲国产传媒在线观看| 亚洲欧美一级二级三级| 亚洲精品影视一区二区|