I have a screen with a UIImageView on top and a UITableView below it -
I want to move up and down the image view when the table view is scrolled so that the table view can take up the entire screen eventually and then come back into its original position when the table view contents are scrolled back all the way to top. I implemented this so far as below -
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("scrolled")
print(scrollView.contentOffset)
let currentOffset = scrollView.contentOffset.y
let netOffset = previousOffset + currentOffset
self.previousOffset = currentOffset
if netOffset > 0 {
self.imageViewTopConstraint.constant = -netOffset
} else if netOffset < 0 {
self.imageViewTopConstraint.constant = netOffset
} else {
self.imageViewTopConstraint.constant = self.imageViewOriginalTop
self.previousOffset = 0.0
}
}
The above code seems to be working fine but when the table view is scrolled all the way down the cells seem to flicker (May be because the scroll events continuously get passed due to bouncing effect when the table view contents are scrolled all the way up or down?)
How can I fix this?