简体   繁体   English

如何获取以编程方式在放置在iOS中的表格视图中的单元格和单元格索引路径中的滚动视图中创建的视图的位置

[英]How to get position of view created programmatically in scrollview placed in cell and cell indexpath in tableview in iOS

This is my code: 这是我的代码:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

 CGFloat pageWidth = scrollView.frame.size.width;

 int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

 NSLog(@"Page No Scroll %i",page);

}

you can get any subview by doing this on UIScrollView . 您可以通过在UIScrollView上执行此操作来获取任何子subview

for(UIView * subView in scrollView.subviews ) 
{ 
     // Here You can Get all subViews of your myScrollView.
}
-(void)scrollViewDidScroll:(UIScrollView *)ScrollView
{
int scrollPositionX = callerScrollView.contentOffset.x;
if (callerScrollView == tbl_ProductView) return;
 for (UITableViewCell *cell in tbl_ProductView.visibleCells) {
UIScrollView cellScrollView = (UIScrollView )[cell viewWithTag:100];
if (callerScrollView == cellScrollView) continue;
NSInteger indexPath = callerScrollView.tag;
//NSLog(@"IndexPath Of Cell: %ld",(long)indexPath);
cellScrollView.contentOffset = CGPointMake(scrollPositionX, 0);
}
//ScollPage Position
static NSInteger previousPage = 0;
CGFloat pageWidth = callerScrollView.frame.size.width;
float fractionalPage = callerScrollView.contentOffset.x / pageWidth;
 NSInteger page = lround(fractionalPage);
  if (previousPage != page)
 {
   previousPage = page;
    NSLog(@"Scrolling Page: %li",(long)page);
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM