简体   繁体   English

超视图转换时防止子视图转换

[英]Preventing Subview from Transforming when its Superview Transforms

I have the following set up. 我有以下设置。 I have a UIView called parentView that holds a UIView called childView . 我有一个名为parentViewUIView ,它包含一个名为childViewUIView parentView can be rotated and resized using some touch gestures which need to be on the parentView . 可以使用需要在parentView上的一些触摸手势来旋转和调整parentView大小。 childView has some drawing code in its drawRect method which needs to updated as the parentView is transformed. childView在其drawRect方法中有一些绘图代码,需要在转换parentView进行更新。

I am noticing when I transform the parentView (scale or rotate), childView automatically gets transformed as well. 我注意到当我转换parentView (缩放或旋转)时, childView自动转换。 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. 问题是,虽然我确实希望在childView上启动旋转变换,但我不希望它是缩放,我宁愿执行它的绘图代码。

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. 我注意到,在转换childView之后,当我在parentView上调用“ setNeedsDisplay ”时,它不会被执行。

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. 这样,转型不会影响孩子。

I had to apply the rotation to the parentView , and then set the bounds property of parentView and childView to resize it. 我必须将旋转应用于parentView ,然后设置parentViewchildView的bounds属性来调整它的大小。 Then I was able to redraw the childView in drawRect successfully. 然后我能够成功地重绘drawRectchildView 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. 虽然我认为如果你在childs superview上设置一个转换,我认为你不得不在它的子视图中使用它。 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. 布伦特的上述情况也可能在某些情况下派上用场。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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