首先,我没有故事板,一切都是程序化的。我有三个TextFields,其中一个隐藏(isHidden = true)在登录按钮后面,登录按钮下面是一个注册按钮。如果点击注册按钮,登录按钮会在注册按钮下滑动,然后隐藏的textField将其isHidden属性设置为false。
我现在的问题是,当点击注册按钮时,登录按钮向下移动并显示文本字段但无法选择,当我尝试选择它时,登录按钮会快速回到原来的位置。
当键盘显示再次显示时,我的视图也会向上移动,我不认为这有帮助。
的TextField:
class SplitterTextField: UITextField, UITextFieldDelegate {
var accessID: String!
required init(frame: CGRect, accessID: String) {
super.init(frame: frame)
self.accessID = accessID
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
private func setup() {
delegate = self
backgroundColor = Color.textFieldBackground
accessibilityIdentifier = accessID
textAlignment = .center
returnKeyType = .done
placeholder = NSLocalizedString("\(accessID!)PlaceHolder", comment: "")
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
resignFirstResponder()
return true
}
}
移动按钮功能:
@objc private func registerButtonTapped() {
if confirmPasswordTextField.isHidden {
animateLoginButton()
} else {
registerNewUser()
}
}
@objc private func loginButtonTapped() {
if !confirmPasswordTextField.isHidden {
animateLoginButton()
} else {
//segue to next vc
}
}
private func animateLoginButton() {
if confirmPasswordTextField.isHidden {
moveLoginButtonDown()
} else {
moveLoginButtonUp()
}
}
private func moveLoginButtonDown() {
//Move loginButton down revealing confirmationPasswordTextView behind it
UIView.animate(withDuration: 0.3, animations: {
self.loginButton.frame.origin.y += Layout.loginButtonYMovement
self.confirmPasswordTextField.isHidden = false
})
}
private func moveLoginButtonUp() {
//Move the loginButton up, when it has finished moving hide the confirmationPasswordTextView
UIView.animate(withDuration: 0.3, animations: {
self.loginButton.frame.origin.y -= Layout.loginButtonYMovement
}, completion: { _ in
self.confirmPasswordTextField.isHidden = true
})
}
查看控制器键盘功能:
func setupKeyboard() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(sender:)), name: NSNotification.Name.UIKeyboardWillShow,object: nil)
NotificationCenter.default.addObserver(self,selector: #selector(keyboardWillHide(sender:)),name: NSNotification.Name.UIKeyboardWillHide,object: nil)
}
@objc private func keyboardWillShow(sender: NSNotification) {
self.view.frame.origin.y = Layout.welcomeScreenKeyboardMovement
}
@objc private func keyboardWillHide(sender: NSNotification) {
self.view.frame.origin.y = 0
}
任何建议都将不胜感激。谢谢,请告诉我是否需要更多上下文。所有视图都使用约束固定,并且不会发生涉及约束的错误。
答案 0 :(得分:1)
按下注册按钮时添加这行代码。
var async = require('async')
var request = require('request')
async.waterfall([
function(cb) {
// send the first request
request.post("https://example.com/first", function (err, resp) {
// send the response to the next function or break in case there was an error
cb(err, resp)
})
},
function(resp, cb) {
// check for the response
if (resp.statusCode === 200) {
// in case the response code is 200 continue to the next function
return cb()
}
// if its not 200 break with the response code as an error
return cb(resp.statusCode)
},
function(cb) {
// send the verify
request.get("https://example.com/statusCheck", function (err, resp, body) {
// send the body of the response to the next function or break in case of an error
cb(err, body)
})
}
], function (err, result) {
// check if there was an error along the way
if (err) {
console.log("there was an error", err)
} else {
// all is good print the result
console.log("result:", result)
}
})
然后尝试选择该字段。 正确设置框架按钮,使它们不会相互混淆。 您可以打印按钮框以便更好地理解。