chaneeii / iOS-Study-Log

✨ iOS에 대해 공부한 것들을 기록합니다 ✨
18 stars 0 forks source link

키보드 처리 #7

Open chaneeii opened 1 year ago

chaneeii commented 1 year ago

https://0urtrees.tistory.com/35 https://wi0214.tistory.com/5

chaneeii commented 1 year ago

화면터치해서 키보드 내리기

Extension 을 구현해주면 된다.


    // 화면터치해서 키보드 숨기기
    func hideKeyboardWhenTappedAround() {
        let tap = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
        tap.cancelsTouchesInView = false
        view.addGestureRecognizer(tap)
    }

    @objc func dismissKeyboard() {
        view.endEditing(true)
    }

사용할때는 요렇게

    override func viewDidLoad() {
        super.viewDidLoad()
        self.hideKeyboardWhenTappedAround() // ✅ 키보드 내리기를 달아주기
        setUI()
    }

https://seons-dev.tistory.com/entry/UIKit-%ED%99%94%EB%A9%B4-%ED%84%B0%EC%B9%98%ED%95%98%EC%97%AC-%ED%82%A4%EB%B3%B4%EB%93%9C-%EB%82%B4%EB%A6%AC%EB%8A%94-%EB%B0%A9%EB%B2%95-textField