0

You can get the center point of a cell within the coordinates of its superview or tableView using:

  CGPoint center = cell.center;

If the tableview's superview is a UIView, how do you get the cell's center point within the coordinates of the superview of the tableview?

Edit:

The cell is in a tableView and the tableView is in self.view. I am mainly concerned about the y coordinate. I did a test to see what the values should be but am not getting the desired result from convertPointToView:

//debugger values appear below each line
CGRect viewRect = self.view.frame;
//(origin = (x = 0, y = 0), size = (width = 320, height = 568))
CGRect tableRect = self.tableView.frame;
//(origin = (x = 0, y = 108), size = (width = 320, height = 411))
 CGPoint prelimcenter = cell.center;
CGPoint center = prelimcenter;
//(x = 160, y = 242)
prelimcenter = [cell convertPoint:prelimcenter toView:self.view];
// (x = 160, y = 526) 

I would expect the difference in the Y coordinate to be about 108 which is the difference in the frames. However, the difference in the points using convertPoint is 284. What could be wrong with my syntax/code?

user1904273
  • 4,562
  • 11
  • 45
  • 96

1 Answers1

0

You can use the convertPoint:toView: method. Here's a link to Apple's documentation.

CGPoint center = cell.center;
center = [cell convertPoint:center toView:yoursuperview];

That should convert it to the specified view's coordinate system.

Pranay
  • 846
  • 6
  • 10
  • Your answer makes sense but it is giving me the wrong result. Would you mind taking a look at my edit and giving your opinion of what coudl be wrong? – user1904273 Feb 15 '19 at 23:11