I need to hide my UISegmentedControl
in my UICollectionView
when the collection is scrolling. Below my snippet code :
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
.....
.....
if (collectionViewMovie.contentOffset.y > 100) {
self.segmentedControl.isHidden = true
} else if (collectionViewMovie.contentOffset.y < 100) {
self.segmentedControl.isHidden = false
}
}
Its work to hide when the collection is scrolling. But sometimes the segmented is not show when I scroll slowly to the top. Its not smooth too when hidden the UISegmentedControl. I read this but its on Objective C. I read this to but its on UIScrollView. Any suggest and answer will help for me. Thanks in Advance
*Edit
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translation(in: self.view).y < 0 {
self.segmentedControl.isHidden = true
} else {
self.segmentedControl.isHidden = false
}
}
Now its always show or hide when scrolling even smooth scroll, but there is stil no animation. Thanks again in advance