使用导航栏时 IQKeyboardManager 问题

IQKeyboardManager issue when using navigation bar

我正在为我的 iOS 应用程序使用 IQKeyboardManager

当我第一次启动该应用程序时,我点击了一个按钮,该按钮取消隐藏包含文本字段的视图。点击文本字段时,IQKeyboardManager 会向上移动整个视图,这样文本字段就不会被键盘隐藏。但是当我导航到其他视图并返回到上一个视图并单击按钮取消隐藏包含文本字段的视图时,IQKeyboardManager 不会向上移动视图。

我无法理解原因。任何建议将不胜感激。

这是better.It不会影响其他VC:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
    [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
}

在Swift

override func viewWillAppear(_ animated: Bool) {
   IQKeyboardManager.shared.enableAutoToolbar = false
   IQKeyboardManager.shared.enable = false
}
    
override func viewWillDisappear(_ animated: Bool) {
   IQKeyboardManager.shared.enableAutoToolbar = true
   IQKeyboardManager.shared.enable = true
}

和Swift5

import IQKeyboardManager

// add This in viewDidLoad
IQKeyboardManager.shared().disabledDistanceHandlingClasses.add(LoginViewController.self)