I have a UITextField
(searchField) at the center of my viewcontroller and I'm creating a thin line by using UIView
(liveView). I create the lineView and its constraints programmatically. The lineView is essentially an underline that grows in width beneath the textField as the user types. Once the user presses enter, I'm adjusting the constraints so the textfield and the view move to the top of the viewcontroller. I got this working, but as the lineView is moving up, it starts fading out and disappears. No idea why this is happening.
func moveUp(){
verticalConstraint = NSLayoutConstraint(item: lineView!, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: searchField, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 6)
lineView!.translatesAutoresizingMaskIntoConstraints = false
let xConstraint = NSLayoutConstraint(item: lineView!, attribute: .centerX, relatedBy: .equal, toItem: searchField, attribute: .centerX, multiplier: 1, constant: 0)
let widthConstraint = NSLayoutConstraint(item: lineView!, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: (lineView?.frame.size.width)!)
view.addConstraints([verticalConstraint!, xConstraint, widthConstraint])
searchBarTopConstraint.constant = 0
UIView.animate(withDuration: 2.00, delay: 0.0, options: [], animations: {
self.view.layoutIfNeeded()
}, completion: { (finished: Bool) in
})
}
When I checkout the view hierarchy, the view is nowhere to be found.