UICollectionView current visible cell index

后端 未结 16 1429
难免孤独
难免孤独 2020-11-29 16:52

I am using UICollectionView first time in my iPad application. I have set UICollectionView such that its size and cell size is same, means only onc

16条回答
  •  执笔经年
    2020-11-29 17:11

    For completeness sake, this is the method that ended up working for me. It was a combination of @Anthony & @iAn's methods.

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
          CGRect visibleRect = (CGRect){.origin = self.collectionView.contentOffset, .size = self.collectionView.bounds.size};
          CGPoint visiblePoint = CGPointMake(CGRectGetMidX(visibleRect), CGRectGetMidY(visibleRect));
          NSIndexPath *visibleIndexPath = [self.collectionView indexPathForItemAtPoint:visiblePoint];
          NSLog(@"%@",visibleIndexPath);
    }
    

提交回复
热议问题