본문 바로가기
🍎 iOS

[iOS/Swift/Library] IQKeyboardManager

by 틴디 2022. 9. 16.
728x90
반응형
  • FirstResponder된 UITextField와 UITextView가 화면에 보이도록 화면 위치를 자동으로 이동 시켜주는 라이브러리
  • AutoTool을 사용하면 키보드의 툴바로 다음 혹은 이전 UITextField나 UITextView로 이동할 수 있는 기능을 제공 함
  • IQkeyboardManager.shared.enable = true 를 AppDelegate나 SceneDelegate에 추가해 줌
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
        IQKeyboardManager.shared.enable = true
        print("IQKeyboardManager start ⌨️")
        return true
    }
}

혹은 SceneDelegate에서

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        
        guard let windowScene = (scene as? UIWindowScene) else { return }
        
        self.window = UIWindow(windowScene: windowScene)
        let tabBarController = BaseTabBarController()
        self.window?.rootViewController = tabBarController
        self.window?.makeKeyAndVisible()
        
        IQKeyboardManager.shared.enable = true
        
    }

 

        IQKeyboardManager.shared.enableAutoToolbar = false
        IQKeyboardManager.shared.shouldResignOnTouchOutside = true
  • enableAutoToolbar는 default 값이 true 인데, true일 경우 키보드의 툴바에 다음 혹은 이전 텍스트 필드로 이동할 수 있는 기능을 제공함. 사용하지 않는 경우 false로
  • shouldResignOnTouchOutside 옵션을 true로 설정 하는 경우 화면 밖을 터치 했을 때 리사인 되면서 키보드를 숨길 수 있는 기능. 직접 제스처를 만들어주지 않아도 되는 편리한 기능 🙌🏻

 

참고 사이트

https://github.com/hackiftekhar/IQKeyboardManager

 

GitHub - hackiftekhar/IQKeyboardManager: Codeless drop-in universal library allows to prevent issues of keyboard sliding up and

Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more. - GitHub - ...

github.com

728x90
반응형

댓글