在我的应用程序中,我想在单击文本字段后显示一个下拉表。但它工作得不好。
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 模拟器,文本字段和表格 View 之间存在一些差距。` 在下面的图像中,堆栈 View 中有文本字段。
/image/JDUkw.jpg
/image/GkQXd.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
/image/fmNNe.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)
关于ios - 显示下拉表时的自动布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62016413/