Forum Archive

View.center not the center?

TutorialDoctor

I am working with the UI module, and I came across an issue where view.center wasn't giving me the center of the view. Some created my own function for getting the center of the view as a tuple.

They return different values.

def Get_Center(frame):
    center = (frame.width/2,frame.height/2)
    return center

print customView.center
print Get_Center(customView)

My function made the UI control go to the center.
Any ideas what is happening?

JonB

center doesn't tell you where the center of your view is in its own coords, it tells you the center in the containing views coords, just like frame, and x and y. If your view's x and y attributes happen to be 0, then you'll get the same answer (assuming you have not used transform to rotate the view, or are doing funny things with bounds)

So, you use center for positioning a view, not for positioning its subviews.