Lostania
Lostania

Reputation: 145

Get position of embedded UIElement in screen coordinates in Swift

In a StoryBoard, I have a UIprogressView embedded in a vertical UIStackView that is itself embedded in a horizontal UIStack view. Finally, this last Horizontal UIStackView is embedded in a vertical UIStack view. I found the path to access the UIprogressView :

self.view.subviews[0].subviews[0].subviews[1].subviews[0]

After many attempts using .convert method, I'm absolutly unable to find the position of my UIProgressView in screens coordinates. I always obtain coordinates that seems relatives to a superview, but never corresponding to it's apparent position on screen. What did I missed ? Thanks.

Upvotes: 0

Views: 520

Answers (1)

Deitsch
Deitsch

Reputation: 2178

Please post how you tried to convert it. Try to apply my example and see if it works for you.

Make an outlet of you progressView and then try to convert its frame to the corresponding frame in the view you need (in my case topMostView).

let progressViewGlobalFrame = progressView.convert(progressView.convert.frame, to: topMostView)

Upvotes: 2

Related Questions