Domanda

I'm a little confused. Let's say I have a UIView named myView, and we have the following block of code:

[myView setTransform:CGAffineTransformMakeScale(2.0f, 2.0f)];
[myView setTransform:CGAffineTransformMakeScale(0.5f, 0.5f)];

Now, if I looked at this code I would assume that this would leave the UIView's size unchanged. However, it actually makes it half of its original size! It seems that UIViews have some sort of "memory" about what their original size was. Is this correct? This also seems like a very weird choice that Apple made, and I was hoping someone could enlighten me about exactly what's going on and why it is the way it is.

Thanks!

È stato utile?

Soluzione

A UIView's frame property is its bounding rectangle in the coordinate space of its superview.

Its bounds property, on the other hand, is the bounding rectangle in the view's own coordinate space.

The halving of the view's size, therefore, would be seen in its frame.size (because its size is halved w.r.t. its superview) but not in its bounds.size (because the view itself still has the same size).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top