gpt4 book ai didi

ios - 出现键盘时快速移动 View

转载 作者:搜寻专家 更新时间:2023-10-31 22:33:16 25 4
gpt4 key购买 nike

我的 View 中有六个 UITextField,我想决定 View 是否必须移动。如何在移动 View 之前检查选择了哪个 TextField?

这就是我显示键盘和移动 View 的代码:

    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)

func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
self.view.frame.origin.y -= keyboardSize.height - 85
}
}

func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
self.view.frame.origin.y += keyboardSize.height - 85
}
}

最佳答案

如果您想知道选择了哪个UITextField,可以使用textFieldDidBeginEditingtextFieldDidEndEditing

func textFieldDidBeginEditing(textField: UITextField!) {
currentSelectedTextField = textField
}

func textFieldDidEndEditing(textField: UITextField!) {
currentSelectedTextField = nil
}

关于如何在选择 UITextField 时管理键盘的引用:https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

关于ios - 出现键盘时快速移动 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35089529/

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