ios - 显示下拉表时的自动布局问题

标签 ios swift xcode uitableview

在我的应用程序中,我想在单击文本字段后显示一个下拉表。但它工作得不好。

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/

相关文章:

ios - 同一 TextView 中的不同文本大小

iOS Facebook Messenger,打开并完成任务后自动关闭链接

ios - 将 UITextField 限制为 Int 输入

xcode - 如何在不启动文本应用程序的情况下发送短信?

xcode - Xcode 的调试导航器的工作方式与 Instruments 分配不同吗?

ios - CodeSign 错误 : entitlements are required for product type 'Static Library' in SDK 'Simulator - iOS 8.4' . 您的 Xcode 安装可能已损坏

ios - ViewController 容器 UIView 的大小

iphone - 通过分段控件选择的 Google MK-map View 和 Mk-map 类型

swift - 为什么静态属性的闭包在赋值时执行?

ios - 变量已写入,但从未读取过?