我该怎么办?解决方案除了上面发布的答案外,您还可以使用视图的tag属性.只需通过xib或通过代码为滚动视图分配一个标记(Int). yourScrollView.tag = 10 然后在scrollview委托方法中检查此标记: func scrollViewDidEndDecelerating(_ scrollView:UIScrollView){如果scrollView.tag == 10 {///您的滚动视图已滚动} 别的 {//集合视图已滚动}} I have a VC that contains a collectionView and a scrollView. I put this code to change current page of pageController by scrolling in scrollView :func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width) self.pageController.currentPage = Int(pageNumber)}It works nice for scrollView but the problem is when i even scroll in collectionView it declares and causes unwanted changing in pageController!What should i do? 解决方案 In addition to the answers posted above, You can make use of the tag property of the view.Just assign a tag (Int) to your scrollview either in xib or via code.yourScrollView.tag = 10And in the scrollview delegate method check for this tag:func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { if scrollView.tag == 10 { ///Your scrollview was scrolled } else { // Collection view was scrolled }} 这篇关于iOS-scrollViewDidEndDecelerating同时为scrollView和collectionView运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 22:55