Get view's frame in UIView that is not superview

David picture David · Jul 13, 2013 · Viewed 8.1k times · Source

I would think this is a simple question, but I cannot seem to find a way to do this.

I have a view that is a subview of my uiviewcontroller. Within that view, I have another view. To clarify, this is the architecture:

>UIViewController.view
--->Subview A
------->Subview B

I want to get the frame of subview b within uiviewcontroller.view.

Is this possible? subviewB.frame gives me the frame of the view within Subview A.

Answer

rmaddy picture rmaddy · Jul 13, 2013

Use the UIView convertRect:toView: method:

CGRect frameRelativeToViewControllerView = [subviewB convertRect:subviewB.bounds toView:viewController.view];