I have material Floating action button (FAB) at right bottom of screen. Also, I have CollectionView inside View. I want below actions to be done.
I've searched everywhere in google.None of questions satisfied my requirements.
don't forget to set collectionView.delegate = self.
extension ViewController: UIScrollViewDelegate{
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == collectoinView{
button.isHidden = scrollView.contentOffset.y > 50
}
}
}
50 is the position of Y from which the button will hide. You can adjust to any number according to your requirement.
Another Way of doing that
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let targetPoint = targetContentOffset as? CGPoint
let currentPoint = scrollView.contentOffset
if (targetPoint?.y ?? 0.0) > currentPoint.y {
print("up")
} else {
print("down")
}
}
with the second approach, there is no need to provide static value. the second approach has been converted to Swift from objective-c Answer