Calculating Visible Index from UIScrollView
I have to add a number of subviews (vertical direction) of variable height to UIScrollView. I want to know the row index of visible subviews when I scroll so I could add subviews for respective row index, how could I get those ?
e.g. the following code would work if you have same HEIGHT subview in the whole scroll view:
///Calculate which cells should now be visible
CGRect visibleBounds = uiScrollView.bounds;
int firstNeededCellIndex = floorf(CGRectGetMinY(visibleBounds)/HEIGHT);
int lastNeededCellIndex = floo开发者_运维百科rf((CGRectGetMaxY(visibleBounds))/HEIGHT);
Thanks
精彩评论