2013-09-06 2 views
1

UITableView가 어느 방향으로 스크롤되었는지 알 수있는 방법이 있습니까? 나는 방향이 아닌 양에 관심이 있습니다.scrollViewWillBeginDragging의 스크롤 량

+0

자세한 정보를 제공해 주실 수 있습니까? 어떤 의미에서 당신이 이것을 요구하는지, 실제 요구 사항은 무엇입니까, 당신이 시도한 방법은 무엇입니까? – Mrunal

+0

서버에서 데이터를 가져 와서 해당 데이터를 내 tableviewcell에 표시하고 있습니다. 하지만 한 번에 10 개의 레코드 만로드하려고합니다. 이 목적을 위해 나는 limit-offset 것을 사용하고있다. 하지만 ios에서이 작업을 수행하는 방법은 분명하지 않습니다. NSUrl에서 한계 오프셋을 설정하고 있습니다. – astuter

+0

비슷한 질문 : 1. http://stackoverflow.com/questions/5137943/how-to-know-when-uitableview-did-scroll-to-bottom-in-iphone 2. http://stackoverflow.com/questions/9786774/ios-dynamic-new-cell-to-the-table-of-tableview – Mrunal

답변

2

contentOffset 속성을 보면 테이블 뷰의 정확한 오프셋을 쉽게 얻을 수 있습니다. 수직 스크롤 들어 보면 :

tableView.contentOffset.y; 

이 당신은이 논리를 사용할 수있는 10 후 부하 이상의 셀의 사용자 요구 사항에 대한 특정 위치

[theTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:savedScrollPosition inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];       
CGPoint point = theTableView.contentOffset; 
point .y -= theTableView.rowHeight; 
theTableView.contentOffset = point; 

에있는 tableview를 취할 수

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView { 
    CGPoint offset = aScrollView.contentOffset; 
    CGRect bounds = aScrollView.bounds; 
    CGSize size = aScrollView.contentSize; 
    UIEdgeInsets inset = aScrollView.contentInset; 
    float y = offset.y + bounds.size.height - inset.bottom; 
    float h = size.height; 
    // NSLog(@"offset: %f", offset.y); 
    // NSLog(@"content.height: %f", size.height); 
    // NSLog(@"bounds.height: %f", bounds.size.height); 
    // NSLog(@"inset.top: %f", inset.top); 
    // NSLog(@"inset.bottom: %f", inset.bottom); 
    // NSLog(@"pos: %f of %f", y, h); 

    float reload_distance = 10; 
    if(y > h + reload_distance) { 
     NSLog(@"load more rows"); 
    } 
} 
+0

감사합니다. 저에게 도움이되었습니다. 작은 도움. 새 데이터를로드하면 tableView의 크기가 증가합니다. 그렇다면 어떻게 높이를 조절할 수 있습니까? 따라서 필요하지 않으면 데이터가로드되지 않습니다. – astuter

+0

당신은 솔루션을 줄 수있는 콘텐츠의 높이에 따라 tableview 프레임을 설정해야합니다. –

0

당신이 구문 이하로 사용하여 찾을 수 있습니다 ...

NSLog(@"scrolled:%f",yourtableview.contentOffset.y);//y for vertical, x for horizontal 
1

당신은 드래그를 시작할 때하고 종료 할 때 UITableViewcontentOffset을 측정 할 필요가있다. 둘 사이의 차이점을 취하면 초기 위치에서 최종 위치로의 변화량을 알려줍니다.

CGPoint oldOffset; 
CGPoint newOffset; 

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 
     oldOffset = scrollView.contentOffset; 
} 

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { 
     newOffset = *targetContentOffset; 
     CGPoint diff = {newOffset.x - oldOffset.x, newOffset.y - oldOffset.y}; 

     // Where diff.x => amount of change in x-coord of offset 
     // diff.y => amount of change in y coord of offset 
} 

희망 하시겠습니까?