我正从目标c移到Swift,任何人都可以指定如何停止键盘以隐藏文本字段。问题是当用户单击屏幕底部附近的最后一个文本字段时,我的视图控制器中有一些文本字段,键盘出现并隐藏了该文本字段。有什么容易解决的问题还是我应该使用滚动视图?
答案 0 :(得分:-1)
使用名为IQKeyboardManager的此库: https://github.com/hackiftekhar/IQKeyboardManager
Install pod file pod 'IQKeyboardManager’ . And in your app delegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = true
IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "Done”
return true
}
}
You can change the following properties of IQKeyboardManager as well
IQKeyboardManager.shared.overrideKeyboardAppearance = true
IQKeyboardManager.shared.keyboardAppearance = .dark
IQKeyboardManager.shared.toolbarBarTintColor = UIColor.cyan
IQKeyboardManager.shared.toolbarDoneBarButtonItemImage = UIImage(named: "<#T##String#>")
IQKeyboardManager.shared.shouldShowToolbarPlaceholder = false
IQKeyboardManager.shared.placeholderFont = UIFont(name: "Times New Roman", size: 20.0)
IQKeyboardManager.shared.shouldResignOnTouchOutside = true
IQKeyboardManager.shared.shouldPlayInputClicks = true //default