scrollView预测滚动停止位置

- (CGPoint)nearestTargetOffsetForOffset:(CGPoint)offset {

    CGFloat pageSize = self.frame.size.width/5;

    NSInteger page = roundf(offset.x / pageSize);

    [self selectModel:_models[page+2]];

    CGFloat targetX = pageSize * page;

    return CGPointMake(targetX, offset.y);

}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {

    CGPoint targetOffset = [self nearestTargetOffsetForOffset:*targetContentOffset];

    targetContentOffset->x = targetOffset.x;

    targetContentOffset->y = targetOffset.y;

}

注意需要关掉pagingEnabled

你可能感兴趣的:(scrollView预测滚动停止位置)