您的当前位置:首页scrollView预测滚动停止位置

scrollView预测滚动停止位置

2024-12-13 来源:哗拓教育

- (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

显示全文