如何在IQKeyboardManager iOS Swift 3中隐藏工具栏

Gij*_*ese 5 uitextfield ios swift ios-keyboard-extension iqkeyboardmanager

我在使用键盘开始键入时使用IQKeyboardManger库滚动文本字段,但我不想显示其库中的默认工具栏.以下是我用过的代码.

override func viewDidLoad() {
        super.viewDidLoad()

        self.chatTextField.inputAccessoryView = [[UIView alloc] init];  //This will remove toolbar which have done button.

        self.chatTextField.keyboardDistanceFromTextField = 8; //This will modify default distance between textField and keyboard. For exact value, please manually check how far your textField from the bottom of the page. Mine was 8pt.    

    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Wol*_*ine 27

您可以在属性下面设置IQKeyboardManager.

我假设您已经在这样的app delegate的didFinishLaunch中启用了IQKeyboardManager

    IQKeyboardManager.sharedManager().enable = true
Run Code Online (Sandbox Code Playgroud)

shouldShowTextFieldPlaceholder to false==>如果要隐藏占位符工具栏部分

shouldHidePreviousNext to false==>如果你想隐藏next和prev按钮等等.

您可以启用在设置didFinishLaunchAppDelegate中这样

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    IQKeyboardManager.sharedManager().enable = true

    IQKeyboardManager.sharedManager().enableAutoToolbar = false
    IQKeyboardManager.sharedManager().shouldShowTextFieldPlaceholder = false
    IQKeyboardManager.sharedManager().shouldHidePreviousNext = false


    return true
}
Run Code Online (Sandbox Code Playgroud)

  • 隐藏下一个上一个键使用:- IQKeyboardManager.sharedManager().previousNextDisplayMode = IQPreviousNextDisplayMode.alwaysHide (2认同)

Bha*_*ani 8

您可以启用或停用工具栏didFinishLaunchingWithOptionsAppDelegate:

IQKeyboardManager.sharedManager().enable = true

IQKeyboardManager.sharedManager.enableAutoToolbar = false
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅属性和函数用法


MrM*_*ins 5

Swift 3shouldResignOnTouchOutside如果在UITextField/ 之外触摸, 您必须使用它来重新签名textField UITextView.

ViewController如果您希望将其添加到特定内容中,ViewController或者覆盖文件中的所有应用程序,请将其添加到您的中AppDelegate.

方法内部:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  IQKeyboardManager.sharedManager().enable = true
  IQKeyboardManager.sharedManager().enableAutoToolbar = false
  IQKeyboardManager.sharedManager().shouldShowToolbarPlaceholder = false
  IQKeyboardManager.sharedManager().shouldResignOnTouchOutside = true
}
Run Code Online (Sandbox Code Playgroud)


Lan*_*ria 5

这是对单个视图控制器执行此操作的方法:

class YourViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        IQKeyboardManager.shared.disabledToolbarClasses = [YourViewController.self]
    }
}
Run Code Online (Sandbox Code Playgroud)

并防止当 IQKeyboardManager 在键盘存在时升高vc时升高 vc:

IQKeyboardManager.shared.disabledDistanceHandlingClasses.append(YourViewController.self)
Run Code Online (Sandbox Code Playgroud)