I've tried to animate the height constraint of the black label on top of the view and I've set a constraint on the white label below that sets the distance from the label above. Then I've tried to animate the height change the black label with the following code (I've tried to ove also the code that changes self.height within the UIView.animateWithDuration block:
@IBOutlet weak var height: NSLayoutConstraint!
@IBAction func resize(sender: AnyObject) {
if self.collapsed {
self.height.constant = 100
} else {
self.height.constant = 0
}
UIView.animateWithDuration(2) {
[unowned self] in
self.view.layoutIfNeeded()
}
collapsed = !collapsed
}
The action resize is invoked by pressing a button.. There is something that is animated, but not what I expected: the label immediately changes its size to 0 or 100. When it becomes 0, the second label slowly moves up to its new position. When black label height is set to 100 then it appears from the top of the screen above the second label, than both of them move down to their final position. The black label has also a constraint above it from the top of the view, so I don't understand why the black label flows down from the top.
Any idea?