UICollectionView with Paging Enable

前端 未结 7 1560
天命终不由人
天命终不由人 2021-02-06 09:06

I have to create Grid view like Appstore iOS app. I want to do this with UICollectionView paging. I have also implemented the code but not able to scroll like that.

Wha

7条回答
  •  半阙折子戏
    2021-02-06 09:39

    If you use pagining in collectionView it will scroll by one page Not one cell. You can disable pagining and implement ScrollViewDelegate

    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
     {
         CGFloat pageW = 300;
        int page = scrollView.contentOffset.x / pageW;
    
        CGFloat newOffset =(page + ((velocity.x > 0)? 1 : -1)) * (pageW - 20);
        CGPoint target = CGPointMake(newOffset, 0);
        targetContentOffset = ⌖
        NSLog(@"end Drag at %f /%i /%f",scrollView.contentOffset.x, page, velocity.x);
    
     }
    

    Only one different from standart paging: If you drag fast Collection will scroll more than one cell. And don't forget to add UIScrollViewDelegate

提交回复
热议问题