如何在iOS Swift中隐藏/查看标题视图表

问题描述 投票:0回答:1

我有静态的UItableview来保存用户表单。我在表格中添加了标题视图以显示电子邮件验证文件,我的问题是标题没有显示隐藏/显示与第一行重叠之间的平滑过渡enter image description here

我想问一下我该如何解决表格标题视图的高而又不能使其重叠的问题代码

@IBOutlet weak var errorView: UIView!

@IBAction func next(_ sender: Any) {
    let newUserEmail = self.txtfEmail.text
    if isValidEmail(newUserEmail!) {
        performSegue(withIdentifier: "addInventryToNewUser", sender: self)
    }
    else {
        cellemail.layer.borderWidth = 2.0
        cellemail.layer.borderColor = UIColor.red.cgColor

        let f = errorView.frame;      
           errorView.frame = CGRect(x: f.origin.x, y: f.origin.y, width: f.width, height: 21);
        errorView.isHidden = false

        lblError.text = "❌ Invalid email address."
    }

}
ios swift uitableview
1个回答
0
投票

您需要应用一些动画才能平滑过渡。方法如下:

@IBAction func next(_ sender: Any) {
    let newUserEmail = self.txtfEmail.text
    if isValidEmail(newUserEmail!) {
        performSegue(withIdentifier: "addInventryToNewUser", sender: self)
    }
    else {
        cellemail.layer.borderWidth = 2.0
        cellemail.layer.borderColor = UIColor.red.cgColor

        UIView.animate(withDuration: 0.5) {
             self.errorView.frame.size.height = 21
        }
        errorView.isHidden = false

        lblError.text = "❌ Invalid email address."
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.