开发者

Calculating Visible Index from UIScrollView

开发者 https://www.devze.com 2023-03-31 13:36 出处:网络
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 in

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

精彩评论

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