I am making an application that has a UIScrollView that expands to a height of 280 and contracts to a height of 0 when dismissed. I used a scroll view because a regular view would not "hide" its subviews after the animation to a 0 height. Initially, before any animating of the Scroll View has occurred, the subviews respond as expected to touch, but after the view's height has been animated at all, all of the subviews stop responding to user touch. I've tried ensuring that the zPosition of all of the subviews is greater than any other view in the view controller, so that isn't the issue. It appears that all of the subviews' frames are within their superview's. Below is the link to a video of my issue:
Here is the code for what occurs when my "parametersButton" is pressed:
@IBAction func parametersButtonPressed(_ sender: Any) {
UIView.animate(withDuration: 0.25, animations: {
if self.parametersExpanded {
//Close searchView, make shadowView transparent
self.searchView.frame.size.height = 0
self.parametersButton.frame = self.parametersButton.frame.offsetBy(dx: 0, dy: -280)
self.searchView.backgroundColor = UIColor.darkGray
self.shadowView.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0)
} else {
//Expand the searchView, darken shadowView
self.searchView.frame.size.height = 280
self.parametersButton.frame = self.parametersButton.frame.offsetBy(dx: 0, dy: 280)
self.searchView.backgroundColor = UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1)
self.shadowView.layer.zPosition = 990
self.shadowView.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.868)
}
}) { (bool) in
}
}
Note that in my application, the searchView is originally dismissed, i.e. having a frame height of 0. For this demonstration, I've made it so that when the application loads for the first time, the view is expanded so I can demonstrate that the subviews respond before animation of their superView. Additionally, there is the shadowView that I use to darken the views behind it, but it is pretty clearly behind the searchView so that isn't the issue.
As per OP comments...
The likely issue was due to explicitly changing the frame(s) of the view elements, which were set up with auto-layout constraints. Common issue, and can cause all sorts of odd errors / conditions.
Changing the animated view collapse / expand methods to changing constraint properties instead of explicit frame changes fixed the problem.