gpt4 book ai didi

ios - 当键盘出现 Swift 时,使用文本字段和按钮向上移动 View

转载 作者:可可西里 更新时间:2023-10-31 23:55:28 26 4
gpt4 key购买 nike

我知道有几个关于这个主题的已发布问题,但没有一个有效。我有一个表格 View ,在它下面有一个包含文本字段和按钮的 UIView。当我的键盘出现时,它覆盖了整个 UIView,使我无法单击“发送”。显示我的应用程序外观的图像:

enter image description here

目前,我的代码是:

 override func viewDidLoad() {
super.viewDidLoad()
inputTextField.delegate = self
inputTextField.layer.cornerRadius = 5
inputTextField.clipsToBounds = true
sendButton.layer.cornerRadius = 5
sendButton.clipsToBounds = true
self.tableView.register(UINib(nibName: "TableViewCell", bundle: nil), forCellReuseIdentifier: "TableViewCell")
loadMsg()
self.hideKeyboardWhenTappedAround()

}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
inputTextField.becomeFirstResponder()
}

当我的键盘出现时,我应该如何将 UIView 连同 UIView 包含的文本字段和按钮一起向上移动?

最佳答案

只需添加 this使用 POD 将库添加到您的项目中,仅此而已。它会自动执行。你不必做任何其他事情。

像那样添加pod

pod 'IQKeyboardManagerSwift'

在 AppDelegate.swift 中,只需导入 IQKeyboardManagerSwift 框架并启用 IQKeyboardManager。

import IQKeyboardManagerSwift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

IQKeyboardManager.shared.enable = true

return true
}
}

作为引用,请查看此网址,https://github.com/hackiftekhar/IQKeyboardManager

关于ios - 当键盘出现 Swift 时,使用文本字段和按钮向上移动 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50325019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com