Reputation: 14527
I have the following set up. I have a UIView
called parentView
that holds a UIView
called childView
. parentView
can be rotated and resized using some touch gestures which need to be on the parentView
. childView
has some drawing code in its drawRect method which needs to updated as the parentView
is transformed.
I am noticing when I transform the parentView
(scale or rotate), childView
automatically gets transformed as well. Problem with this is, while I do want the rotate transform to be initiated on the childView
, I don't want it to be scale, I'd rather execute its drawing code.
So my question is, what is a good way to handle this situation? I notice when I call "setNeedsDisplay
" on my childView
after parentView
is transformed, it doesn't get executed.
Upvotes: 1
Views: 1524
Reputation: 14527
I had to apply the rotation to the parentView
, and then set the bounds property of parentView
and childView
to resize it. Then I was able to redraw the childView
in drawRect
successfully. Bottom line is though I think if you set a transform on a childs superview, I think you're stuck having to live with it in its subviews. I tried setting the transforms separately and all of the timing of the transforms got screwed up. The above situation from Brent might also come in handy for certain situations.
Upvotes: 1
Reputation: 17861
Don't transform the parent view; transform a sibling of the child view.
In other words, your current set up looks like this:
transformedView
childView
Instead, do this:
parentView
transformedView
childView
That way the transformation won't affect the child.
Upvotes: 2