Reputation: 195
I have static UItableview to hold user form. I added header view in the table to show email validation files my problem is the header does not show a smooth transition between hiding/show and overlap with the first row
I want to ask how I can fix the hight of the table header view and does not make it overlap code
@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."
}
}
Upvotes: 1
Views: 313
Reputation: 1712
I will combine the two answer:
@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
}
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
// your code to hide view here
}
errorView.isHidden = false
lblError.text = "❌ Invalid email address."
}
}
Upvotes: 1
Reputation: 69
I have no enough reputation to add a comment, but the answer on "how to hide it after 5 seconds?" Is:
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
// your code to hide view here
}
Upvotes: 2
Reputation: 16341
You need to apply some animation for a smooth transition. Here's how:
@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."
}
}
Upvotes: 2