준코딩

[ios/Swift] 화면 터치 시 키보드 내리기 본문

프로그래밍/IOS (Swift)

[ios/Swift] 화면 터치 시 키보드 내리기

Ljunhyeob - App Dev 2023. 1. 9. 17:32

올라오는 키보드 때문에 화면이 가려져 다음 액션이 불가한 경우 화면을 터치해서 키보드를 내리는 코드입니다

 

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

      self.view.endEditing(true)

}

 

위 코드를 viewController 아무곳이나 넣으시면 됩니다 

 

//
//  ViewController.swift
//  KeyboardDown
//
//  Created by 이준협 on 2023/01/09.
//

import UIKit

class ViewController: UIViewController {
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){

         self.view.endEditing(true)

   }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }


}

https://github.com/Ljunhyeob/keyboardDown

 

GitHub - Ljunhyeob/keyboardDown: 키보드 내리기

키보드 내리기. Contribute to Ljunhyeob/keyboardDown development by creating an account on GitHub.

github.com

 

Comments