简体   繁体   English

键盘弹出时如何向上移动文本字段

[英]How to move text field up when keyboard pops up

I am moving in from objective c to swift can anyone specify how to stop keyboard to hide the textfield .我正在从目标 c 转移到 swift 任何人都可以指定如何停止键盘以隐藏文本字段。 The problem is I have some text field in my view controller when the user click on last text field near to bottom of screen the keyboard appears and hide the textfield .问题是当用户单击靠近屏幕底部的最后一个文本字段时,我的视图控制器中有一些文本字段,键盘出现并隐藏该文本字段。 is there any easy to solve this or should i have to use scroll view ?有什么容易解决的问题,还是我必须使用滚动视图?

Use this library called IQKeyboardManager: https://github.com/hackiftekhar/IQKeyboardManager使用这个名为 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM