0

I have a UITableView. And for each UITableViewCell I have subviews such as UIImage and UILabel.

Now I want to find the exact coordinate (Preferably the CGRect) of one of the UIImages when I only have the reference to it.

One way I can think of is somehow get the coordinate of the parent UITableViewCell; Get the location of the UIImage within the cell, and then add them up.

But I am not sure if this is the best way. Isn't there an easy way to just take any UIView type and get its coordinate within the entire view, even if it's a subview of a UITableViewCell?

Vlad
  • 8,038
  • 14
  • 60
  • 92
  • possible duplicate http://stackoverflow.com/questions/7028850/ios-get-location-of-a-view-in-a-window – JAB Oct 14 '16 at 18:38

1 Answers1

1

UIView has a set of instance methods that let you convert frames and points from one coordinate system to another. Documentation here

This could work in your parent View controller:

let convertedRect = cell.convert(cell.myImageView.frame, to: self.view)
Dima
  • 23,484
  • 6
  • 56
  • 83