tableview到制定位置,不可滾動

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offset = scrollView.contentOffset.y;
    //停在某個位置
    if (offset >= 300) {
        [self.tableView setContentOffset:CGPointMake(0, 300) animated:NO];
    }
    NSLog(@"offset = %f",offset);
}

獲取cell在屏幕的位置

//獲取當前cell在tableview中的位置
 CGRect rectintableview=[table rectForRowAtIndexPath:indexpath];
 //獲取當前cell在屏幕中的位置
CGRect rectinsuperview=[table convertRect:rectintableview fromView:[table superview]];

convertRect: toViewt和convertRect: fromView

方法 相同點 不同點
newRect = [someView convertRect:rect toView:toView]; 只改變rect的origin,size不變 rect是相對於someView的,以toView爲座標系重新計算rect的值
newRect = [someView convertRect:rect fromView:fromView]]; 只改變rect的origin,size不變 rect是以fromView爲座標系下的值,將rect轉爲以someView爲座標系的值
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章