第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Swift觸摸任意位置以關(guān)閉iOS鍵盤

使用Swift觸摸任意位置以關(guān)閉iOS鍵盤

慕田峪7331174 2019-10-12 14:31:33
我一直在尋找這個,但似乎找不到。我知道如何使用來關(guān)閉鍵盤,Objective-C但是我不知道如何使用Swift?有人知道嗎?
查看完整描述

3 回答

?
Smart貓小萌

TA貢獻1911條經(jīng)驗 獲得超7個贊

有關(guān)以下有關(guān)如何使用Swift在Xcode 6.1中關(guān)閉鍵盤的問題的答案:


import UIKit


class ItemViewController: UIViewController, UITextFieldDelegate {


    @IBOutlet var textFieldItemName: UITextField!


    @IBOutlet var textFieldQt: UITextField!


    @IBOutlet var textFieldMoreInfo: UITextField!



    override func viewDidLoad() {

        super.viewDidLoad()


        textFieldItemName.delegate = self

        textFieldQt.delegate = self

        textFieldMoreInfo.delegate = self

    }


                       ...


    /**

     * Called when 'return' key pressed. return NO to ignore.

     */

    func textFieldShouldReturn(textField: UITextField) -> Bool {

        textField.resignFirstResponder()

        return true

    }



   /**

    * Called when the user click on the view (outside the UITextField).

    */

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

        self.view.endEditing(true)

    }


}


查看完整回答
反對 回復(fù) 2019-10-12
?
慕運維8079593

TA貢獻1876條經(jīng)驗 獲得超5個贊

Swift 4工作

如下創(chuàng)建擴展名并hideKeyboardWhenTappedAround()在Base視圖控制器中調(diào)用。


//

//  UIViewController+Extension.swift

//  Project Name

//

//  Created by ABC on 2/3/18.

//  Copyright ? 2018 ABC. All rights reserved.

//


import UIKit


extension UIViewController {

    func hideKeyboardWhenTappedAround() {

        let tapGesture = UITapGestureRecognizer(target: self, 

                         action: #selector(hideKeyboard))

        view.addGestureRecognizer(tapGesture)

    }


    @objc func hideKeyboard() {

        view.endEditing(true)

    }

}


查看完整回答
反對 回復(fù) 2019-10-12
  • 3 回答
  • 0 關(guān)注
  • 868 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號