在我的应用程序中,我想在点击文本字段后显示一个下拉表。但它是不工作的好。
tableViewOne.snp.updateConstraints { (make) in
let superViewOriginY: CGFloat = (textField.superview?.frame.origin.y)!
let textFieldMaxY: CGFloat = textField.frame.maxY
let navigationHeight: CGFloat = self.navigationController!.navigationBar.frame.size.height
let textFieldHeight = textField.frame.height
let tableViewOneTopPsition = superViewOriginY + textFieldMaxY + navigationHeight + textFieldHeight
make.top.equalTo(tableViewOneTopPsition)
make.left.equalTo(15)
make.right.equalTo(-15)
make.height.equalTo(0)
}
self.view.layoutIfNeeded()
UIView .animate(withDuration: 0.4, animations: {
self.tableViewOne.snp.updateConstraints({ (make) -> Void in
make.height.equalTo(170)
})
self.view.layoutIfNeeded()
}, completion: nil)
通过编写这段代码,它可以在iphone 11 Max模拟器上工作。但是对于iphone 8 plus模拟器来说,文本字段和表格视图之间有一些差距。"在下面的图片中,堆栈视图里面有文本字段。
https:/i.stack.imgur.comJDUkw.jpg
https:/i.stack.imgur.comGkQXd.png。
First one image is the iphone 11max pro image
and the second one is the iphone 8 plus image
如果我会写
make.top.equalTo(textFieldMaxY)
the i will be
https:/i.stack.imgur.comfmNNe.jpg
请帮助我克服这个问题。
添加这一行
tableViewOne.snp.updateConstraints { (make) in
make.top.equalTo(textField.snp.bottom).offset(5)
make.left.equalTo(15)
make.right.equalTo(-15)
make.height.equalTo(0)
}
UIView .animate(withDuration: 0.4, animations: {
self.tableViewOne.snp.updateConstraints({ (make) -> Void in
make.height.equalTo(170)
})
self.view.layoutIfNeeded()
}, completion: nil)
确保你的约束条件是正确的。要修复您指定的错误,您可以更改 topAnchor
的约束。tableViewOne
到 bottomAnchor
的 textField
. 不要计算框架,以给 topAnchor
,而不是给副官视图的约束。
tableViewOne.topAnchor.constraint(equalTo: textField.bottomAnchor).isActive = true
添加时,请删除这一行。
make.top.equalTo(tableViewOneTopPsition)