MohammadReza MohammadReza - 3 months ago 10
iOS Question

Detect when Scrollview Scrolling not tableview scrolling

I have a scrollview inside tableview (tableview's header) and I want to call this action when scroll finish:

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {

let pageNumber = round(bookScrollView.contentOffset.x / bookScrollView.frame.size.width)
pageControl.currentPage = Int(pageNumber)

print("scroll")
}


when I scroll bookScrollView nothing happen, but when table view scroll this function run.

How I detect when bookScrollView scroll and run function?

thanks

Answer

Here, you can define, scrollOfTable, or you can also define TAG property. identify and only scroll when scrollview comes in, not tableview.

You also need to check, if your scrollView is setting delegate

self.vsScrollView.delegate = self

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    if scrollView == scrollOfTable {

    }
    else if scrollView == scrollOfScrollView {

    }
    else {
        //something else
    }

}