How to solve keyboard problems in Swift 3?

前端 未结 3 1672
有刺的猬
有刺的猬 2021-01-26 08:34

The problem is that when I try to write in the text fields the keyboard cover them up. How can I scroll the text field up to see what am I writing. I have below lines of code to

3条回答
  •  时光取名叫无心
    2021-01-26 09:21

    How can I scroll the text field up to see what am I writing

    This can be achieved in two ways:

    1. You can manage your frame programmatically on keyboard hide and show like @Taichi Kato
    2. You can integrate libraries which serves the same purpose. One such library is IQKeyBoardManager with its Swift variant as IQKeyboardManagerSwift You can find it on GitHub and cocoapods

    To achieve follow the below steps :

    SWIFT 3

    1. Just install IQKeyboardManagerSwift from Github or cocoapods

    2. Import IQKeyboardManagerSwift in Appdelegate

    3. Add the below lines of code in AppDelegate didFinishLaunchingWithOptions method.

      IQKeyboardManager.sharedManager().shouldResignOnTouchOutside = true;
      

    Objective-C

    1. Install IQKeyBoardManager via any medium
    2. Import #import "IQKeyboardManager.h" in Appdelegate
    3. Add the below lines of code in AppDelegate didFinishLaunchingWithOptions method.

      IQKeyboardManager.sharedManager.shouldResignOnTouchOutside = true;
      

    And this is Done. This is the only code which you need to write.

提交回复
热议问题