Getting the exact location of a UITableViewCell

后端 未结 9 593
滥情空心
滥情空心 2021-01-30 20:10

Given a UITableView, how can I find the location of a specific UITableViewCell? In other words, I want to get its frame relative to my iPhone screen, n

9条回答
  •  悲&欢浪女
    2021-01-30 20:50

    try it in

    didSelectRowAtIndexPath method

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    
            // get current location of selected cell
    
            CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
    
            CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];
    
    
             NSLog(@"Cell Y Is %f",rectInSuperview.origin.y);
    
            NSLog(@"Cell X Is %f",rectInSuperview.origin.x);
    

提交回复
热议问题