UIScrollView滑动获取当前页

2020-05-15  本文已影响0人  af4e8a35bc89
UIScrollView滑动获取当前页
#pragma mark --  UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    CGFloat pageWidth = scrollView.frame.size.width;
    
    int currentPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

    if (currentPage == self.dataArray.count - 1) {
        NSLog(@"最后一页");
    }else if (currentPage == 0){
        NSLog(@"第一页");
    }else{
        NSLog(@"中间页");
    }

}
上一篇下一篇

猜你喜欢

热点阅读