YichenBman
YichenBman

Reputation: 5661

Get center of UIView contained within UIStackView

UIStackView in iOS 9 has been great.

However, when trying to access the center property of a UIView that fills one of the lower child views within the UIStackView, xcode returns (187.5, 30.5)

The view is actually located at the bottom of the screen. More like (208, 673) on my 5.5" iPhone

I believe xcode is returning the center point in relation to the containing stack child view, however I need to know where the view is in relation to the whole screen.

How then would I find the point on the screen my view is located?

Upvotes: 1

Views: 627

Answers (1)

Anibal Itriago
Anibal Itriago

Reputation: 1051

You can get the frame rect of the UIStackView cell simply getting the frame of the superview (Supposing that the UIStackView's parent is the main view). Something like:

UIView
   |
   +-- UIStackView
          |
          +-- targetUIView *

So, to know the position of the targetUIView relative to the main UIView, you should call something like:

CGRect location = targetUIView.superview.frame;

Regards

Upvotes: 1

Related Questions