之后更改 StackView 元素的高度
Change height of StackView element afterwards
我在 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()
但这没有任何作用...我还想要某种动画,没什么特别的,它最终应该看起来很流畅。
有谁知道如何解决这个问题??
对于要打破的高度,这意味着还有另外 1 个高度限制,因为这条线
passwordTextField.heightAnchor.constraint(equalToConstant: 140).isActive = true
又创建了1个,需要添加变量
var heCon:NSLayoutConstraint!
heCon = passwordTextField.heightAnchor.constraint(equalToConstant: 140)
heCon.isActive = true
然后使用它的常量
heCon.constant = 100
theStackView.layoutIfNeeded()
我在 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()
但这没有任何作用...我还想要某种动画,没什么特别的,它最终应该看起来很流畅。
有谁知道如何解决这个问题??
对于要打破的高度,这意味着还有另外 1 个高度限制,因为这条线
passwordTextField.heightAnchor.constraint(equalToConstant: 140).isActive = true
又创建了1个,需要添加变量
var heCon:NSLayoutConstraint!
heCon = passwordTextField.heightAnchor.constraint(equalToConstant: 140)
heCon.isActive = true
然后使用它的常量
heCon.constant = 100
theStackView.layoutIfNeeded()