6

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.

Daniel Kappacher
  • 472
  • 1
  • 6
  • 15
  • You could try.In your animation block use UIViewAnimationOption.autoReverse, UIViewAnimationOption.repeat. This will run your animation forever you like.... – Joe Oct 17 '16 at 01:22
  • @Joe Thanks for your answer but that didn't solve the problem – Daniel Kappacher Oct 17 '16 at 06:23

0 Answers0