简体   繁体   中英

UIView center, origin, and frame not making sense

I have the following stats for a UIView in my app:

Frame: {{0, 111.0900252548883}, {374.99999999999994, 444.81994949022345}} 
AnchorPoint: {0.54933333333333334, 0.50329166666666669} 
Center: {193.18185551317976, 315.35327169496856}

The UIView has had a transform performed on it and while I know in the Apple docs it says the frame gets invalidated after a transform, the above numbers are still correct as I've verified them otherwise.

My question is, how do these numbers make sense? For instance, if the x origin of the frame starts at 0, and ends at 375, how is the x center 193.18185551317976 when the anchor point is 0.54933333333333334? Shouldn't the x center be 374.99999999999994 * 0.54933333333333334 = 205.99999999999997?

Anchor Point doesn't affect position at all. It only offsets the texture from the node's position. The problem with changing the anchorPoint is that it seemingly does affect position. The real problem usually comes later on, when you realise that changing the anchorPoint from its default also affects other node attributes. For example, rotation uses the anchorPoint as its center point. Scaling uses the anchorPoint as its centerPoint. Its a bit confusing. Try out this wonderful article about anchorPoint. Helped me a lot to understand it clearly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM