⌨ IQKeyboardManager 사용 중 실기기 UI 오류 해결

임클·2025년 7월 2일

⌨ IQKeyboardManager 사용 중 실기기 UI 오류 해결

  • 문제
    - IQKeyboardManager v6.5.0 사용
    - 키패드가 UI를 가리는 것을 대비해 UI를 위로 올려주는 과정에서 화면이 덜컹거림을 확인
    - 기타 참고 블로그에서는 해당 내용을 공유된 자료의 부재
    - 해당 라이브러리가 Singleton 구조로 사용됨을 확인 후 수정 가능한 값을 확인 후 해결

    	```swift
    
    	@objcMembers public final class IQKeyboardManager: NSObject {
    	...
    	If YES, then calls 'setNeedsLayout' and 'layoutIfNeeded' on any frame 	update of to viewController's view.
    	    */
    	public var layoutIfNeededOnUpdate: Bool = false
    	...
    	```
  • 원인
    - UI가 흔들리는 원인은 View가 키패드의 높이를 즉각적으로 반영을 하지 못함이었음

  • 해결
    - layoutIfNeededOnUpdate 값을 true 로 변경해 사용

    	```swift
    	class AppDelegate: UIResponder, UIApplicationDelegate {
    		func application( _ application: UIApplication,
    	didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    		IQKeyboardManager.shared.isEnabled = true
    	    IQKeyboardManager.shared.resignOnTouchOutside = true
    		IQKeyboardManager.shared.layoutIfNeededOnUpdate = true
    	```

0개의 댓글