scrollview自定义pageEnable

#pragma mark 
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    _startY = scrollView.contentOffset.y;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (decelerate) return;
    [selfdealPageEnableWithScrollView:scrollView];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [selfdealPageEnableWithScrollView:scrollView];
}
#pragma mark 处理scrollView翻页效果
- (void)dealPageEnableWithScrollView:(UIScrollView *)scrollView{
    static CGFloat halfH;
    halfH = halfH ? halfH : scrollView.bounds.size.height;
    NSLog(@"-----------------%zi%zi%zi",scrollView.contentOffset.y > (_otherPageStartY - halfH),_startY < scrollView.contentOffset.y,_startY < (_otherPageStartY - halfH));
    NSLog(@"*****************%zi%zi%zi",scrollView.contentOffset.y < _otherPageStartY,_startY > scrollView.contentOffset.y,_startY >= _otherPageStartY);
    if (scrollView.contentOffset.y > (_otherPageStartY - halfH +60) &&
        _startY < scrollView.contentOffset.y &&
        _startY < _otherPageStartY
//        _isSecondPage) {//此处还可以用一个BOOL类型来记录是否是处在第一页,代替后面两个判断
        [UIViewanimateWithDuration:0.5animations:^{
            [scrollView setContentOffset:CGPointMake(0,_otherPageStartY)];
        } completion:^(BOOL finished) {
            NSLog(@"进入第二页------->%f",scrollView.contentOffset.y);
        }];
    }
    else if (scrollView.contentOffset.y < (_otherPageStartY -30) &&
             _startY > scrollView.contentOffset.y &&
             _startY >= (_otherPageStartY - halfH)
//        !_isSecondPage){
        [UIViewanimateWithDuration:0.5animations:^{
            [scrollView setContentOffset:CGPointZero];
        } completion:^(BOOL finished) {
            NSLog(@"进入第一页------->%f",scrollView.contentOffset.y);
        }];
    }

你可能感兴趣的:(iOS,代码)