I have a UICollectionView which is pinned to Top Layout Guide (I use NavigationController so it's pinned to the Navigation Bar) and aligned to the bottom of an image which it overlays.
I am hiding the Navigation Bar and animating the Image position, which means because of the constraints the CollectionView is moving too.
In scrollViewDidScroll delegate method of my scrollView I am animating them like so:
if scrollView.panGestureRecognizer.translation(in: scrollView).y > 0 {
//scrolling up
navigationController?.setNavigationBarHidden(false, animated: true)
UIView.animate(withDuration: 0.2, animations: {
self.topImageContraintToTop.constant = 0
self.view.layoutIfNeeded()
})
} else {
//scrolling down
navigationController?.setNavigationBarHidden(true, animated: true)
UIView.animate(withDuration: 0.2, animations: {
self.topImageContraintToTop.constant = -(self.navigationController?.navigationBar.bounds.size.height)! - 10
self.view.layoutIfNeeded()
})
}
So everytime this animation is happening, the visible cells of the CollectionView are briefly flashing/blinking.
I have searched hours for solving but so far nothing really helped.
I'd appreciate any kind of approach for this problem.