【发布时间】:2020-03-02 21:54:32
【问题描述】:
我在ScrollView 里面有一个StackView,在里面我有几个TextFields。当该特定文本字段开始编辑时,我想更改textField.height 之一。
我在 textFieldShouldBeginEditing 内部尝试过,但 XCode 破坏了 height.constraint。
//delegate Methode für Password Textfield
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
switch textField {
case passwordTextField:
eyeButtonOne.isHidden = false
passwordTextField.addSubview(checkLetterLabel)
checkLetterLabel.addSubview(checkLetterImage)
passwordTextField.addSubview(checkNumberLabel)
checkNumberLabel.addSubview(checkNumberImage)
passwordTextField.addSubview(checkLengthLabel)
checkLengthLabel.addSubview(checkLengthImage)
checkLetterLabel.topAnchor.constraint(equalTo: passwordTextField.bottomAnchor, constant: 5).isActive = true
checkLetterLabel.leadingAnchor.constraint(equalTo: checkLetterImage.leadingAnchor, constant: 13).isActive = true
checkLetterImage.leadingAnchor.constraint(equalTo: passwordTextField.leadingAnchor).isActive = true
checkLetterImage.centerYAnchor.constraint(equalTo: checkLetterLabel.centerYAnchor).isActive = true
checkLetterImage.heightAnchor.constraint(equalToConstant: 10).isActive = true
checkLetterImage.widthAnchor.constraint(equalToConstant: 10).isActive = true
checkNumberLabel.topAnchor.constraint(equalTo: checkLetterLabel.bottomAnchor, constant: 1).isActive = true
checkNumberLabel.leadingAnchor.constraint(equalTo: checkNumberImage.leadingAnchor, constant: 13).isActive = true
checkNumberImage.leadingAnchor.constraint(equalTo: passwordTextField.leadingAnchor).isActive = true
checkNumberImage.centerYAnchor.constraint(equalTo: checkNumberLabel.centerYAnchor).isActive = true
checkNumberImage.heightAnchor.constraint(equalToConstant: 10).isActive = true
checkNumberImage.widthAnchor.constraint(equalToConstant: 10).isActive = true
checkLengthLabel.topAnchor.constraint(equalTo: checkNumberLabel.bottomAnchor, constant: 1).isActive = true
checkLengthLabel.leadingAnchor.constraint(equalTo: checkLengthImage.leadingAnchor, constant: 13).isActive = true
checkLengthImage.leadingAnchor.constraint(equalTo: passwordTextField.leadingAnchor).isActive = true
checkLengthImage.centerYAnchor.constraint(equalTo: checkLengthLabel.centerYAnchor).isActive = true
checkLengthImage.heightAnchor.constraint(equalToConstant: 10).isActive = true
checkLengthImage.widthAnchor.constraint(equalToConstant: 10).isActive = true
passwordTextField.heightAnchor.constraint(equalToConstant: 140).isActive = true
theStackView.layoutIfNeeded()
break
case passwordWiederholenTextField:
eyeButtonTwo.isHidden = false
break
default:
break
}
return true
}
现在passwordTextField beginsEditing 时所有项目都在显示,但高度没有改变......
正如你所看到的,我也打电话给layoutIfNeeded(),但这没有任何作用......我还想要某种动画,没什么特别的,它最终应该看起来很流畅。
有谁知道如何解决这个问题?
【问题讨论】:
标签: ios swift uitextfield uistackview