亚洲国产精品成人无码区,公天天吃我奶躁我的比视频,亚洲国产欧美视频亚洲国产精品一区二区成人片不卡,天天躁日日躁狠狠躁视频2021,起视碰看97视频在线少妇久久久久久人妻无码, 芒果乱码一线二线三线新区 ,亚洲熟妇无码AⅤ不卡在线播放,人妻少妇乱子伦无码专区

400-800-9385
網站建設資訊詳細

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

發(fā)表日期:2016-01-07 00:00:00   作者來源:方維網絡   瀏覽:6748   標簽:APP開發(fā)    IOS    

如果你是剛從網站建設行業(yè)轉到APP開發(fā),那么你會覺得不可思議,隱藏鍵盤這么簡單的事情,還要這樣大費周張。先不牢騷了,以上是方維網絡的解決經驗:

正常情況下,只要觸摸焦點放在輸入框如textField\textView上,自動會彈出鍵盤,所以,隱藏鍵盤的最終方法就是讓控件失去焦點。

textField.resignFirstResponder()
textView.resignFirstResponder()
 

用例一、TextField按Enter鍵隱藏

實現委托UITextFieldDelegate 方法
func textFieldShouldReturn(textField: UITextField) -> Bool {
      textField.resignFirstResponder()
      return true
}

用例二、點擊其他任意地方隱藏

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.textField.resignFirstResponder()
        self.textView.resignFirstResponder()
}
 

用例三、點擊手勢隱藏

let tapGesture:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "hideKeyboard:")
 
 
        self.view.addGestureRecognizer(tapGesture)
 
func hideKeyboard(sender: UITapGestureRecognizer) {
        self.SearchBar1.resignFirstResponder()
}
 

用例四、滾動tableView隱藏

func scrollViewDidScroll(scrollView: UIScrollView) {
        self.SearchBar1.resignFirstResponder()
}
 

用例五、通過鍵盤通知事件在其上方添加按鈕


IOS鍵盤
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()
        }
    }
 
如沒特殊注明,文章均為方維網絡原創(chuàng),轉載請注明來自http://m.oulysa.com/news/2846.html
亚洲成a人片在线播放| 亚洲AV无码国产成人久久强| 欧美丰满熟妇XXXX性多毛| 3d日本无修肉动漫在线观看| 五月六月综合欧美网站| 真实国产乱子伦高清对白直播| 欧美极品aⅴ影院天天视频| 亚洲精品国产成人一区二区| 国产精品国产三级国产剧情| 久久996热精品xxxx,成人毛片在线视频| 国产一区二区三区精品视频| 国产综合视频在线观看| 国产1区在线看你懂得| 夜夜夜夜曰天天天天| 国产三级韩国三级日产三级| 麻豆传煤一区免费入站口| 国产综合 亚洲日韩中文| 久久精品国产亚洲AV超碰| 免费看女人与公拘交酡过程| 国产精品一区二区在线观看| 国产精品VA无码一区二区| 亚洲国产一区在线精选| 亚洲一区二区三区国产精华液| 少妇私密会所按摩到高潮呻吟| 日本丰满熟妇BBXBBXHD| 久久这里只精品国产免费99热4| 欧美极品欧美精品欧美视频| 日本韩国免费在线手机电影| 国产超碰人人爽人人做人人添| 国产毛片一区亚洲s色大片| 国产成人精品一区二区三| 在线观看中文字幕一区二区三区| 好吊视频一区二区三区| 国产精品视频久久久久久久久久| 伊人久久大香线蕉综合网站| 亚洲AV无码乱码国产麻豆| 国产 中文 制服丝袜 另类,| 欧美特大黄一级AA片片免费| 99久久久国产精品免费电影影片| 国产chinese男男gay视频网| 香蕉久久高清国产精品免费|