UIScrollView: single tap scrolls it to top

后端 未结 5 1782
不知归路
不知归路 2021-01-03 04:25

I have the UIScrollView with pagingEnabled set to YES, and programmatically scroll its content to bottom:

CGPoint contentOffset = scrollView.contentOffset;
c         


        
5条回答
  •  囚心锁ツ
    2021-01-03 04:59

    This small hack prevents the UIScrollView from scrolling when tapped. Looks like this is happening when the scroll view has paging enabled.

    In your UIScrollView delegate add this method:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        scrollView.pagingEnabled = self.scrollView.contentOffset.x < (self.scrollView.contentSize.width - self.scrollView.frame.size.width);
    }
    

    This disables the paging when the scroll view reaches the right end in horizontal scrolling (my use case, you can adapt it to other directions easily).

提交回复
热议问题