How to get the frame of a view inside another view?

cyclingIsBetter picture cyclingIsBetter · Nov 10, 2011 · Viewed 41.8k times · Source

I have an UIImageView in the self.view (the main View) and inside it there is a UIButton. I want to know what's the frame of UIButton in self.view not in UIImageView.

Answer

beryllium picture beryllium · Nov 10, 2011

I guess you are looking for this method

– convertRect:toView:

// Swift
let frame = imageView.convert(button.frame, to: self.view)

// Objective-C
CGRect frame = [imageView convertRect:button.frame toView:self.view];