开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜