stevenpcurtis
stevenpcurtis

Reputation: 2001

Convert UIView frames to self.view coordinate space

Because my frames are in stackviews, my UI elements are returning their frame in the superview coordinate system (that is, the stackview)

I want to return them in the self.view coordinate space.

Ho

    print ("untf frame",self.view.convert(usernameTextField.frame, to: self.view ) )
    print ("pwtf frame",self.view.convert(passwordTextField.frame, to: self.view ) )

both return the same values.

Of course I can see that passwordTextField is 50 down from username.

What am I doing wrong?

Upvotes: 0

Views: 387

Answers (1)

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16466

It is wrong

print ("untf frame",self.view.convert(usernameTextField.frame, to: self.view ) )
print ("pwtf frame",self.view.convert(passwordTextField.frame, to: self.view ) )

Your usernameTextField and passwordTextField is subview of stackview so you need to convert it to self.view Use like this

print ("untf frame",self.stackview.convert(usernameTextField.frame, to: self.view ) )
print ("pwtf frame",self.stackview.convert(passwordTextField.frame, to: self.view ) )

Upvotes: 1

Related Questions