So I have quite a simple task: animate a view to appear (height goes from zero to full height), then it has to disappear animatedly (collapse, height goes to zero). It looks like this:
Implementation is very simple: we give the view a fixed height constraint, then animate it 0->fullHeight, fullHeight->0.
notificationView.heightConstraint.constant = intrinsicHeight
UIView.animateWithDuration(0.25, animations: {
view.layoutIfNeeded()
}) { (finished) in
guard finished else { return }
notificationView.heightConstraint.constant = 0
UIView.animateWithDuration(0.25, delay: 3, options: .AllowUserInteraction, animations: {
notificationView.superview!.layoutIfNeeded()
}, completion: nil)
}
The trouble is that a UIButton
contained in the notification doesn't receive any touches because notification's height is set to 0.
I guess, an alternative would be to use NSTimer
or dispatch_after
, but that would make things a little bit more complicated and I don't want that.
The question is: can I preserve user interaction using current approach?