防止子视图在其超级视图变形时发生变形 [英] Preventing Subview from Transforming when its Superview Transforms

查看:99
本文介绍了防止子视图在其超级视图变形时发生变形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了以下设置。我有一个 UIView 名为 parentView ,其中包含一个 UIView childView 。可以使用 parentView 上的某些触摸手势来旋转和调整 parentView 的大小。 childView 在其drawRect方法中有一些绘图代码,随着 parentView 的转换,需要对其进行更新。

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.

当我转换 parentView (缩放或旋转), childView 也会自动转换。这样做的问题是,虽然我确实希望在 childView 上启动旋转变换,但我不希望它缩放,我宁愿执行其绘制代码。

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.

所以我的问题是,处理这种情况的好方法是什么?我注意到当我在 parentView childView 上调用 setNeedsDisplay 时,

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.

推荐答案

我不得不将旋转应用于 parentView ,然后设置 parentView childView 的bounds属性以调整其大小。然后,我能够成功地在 drawRect 中重新绘制 childView 。最重要的是,虽然我认为如果您对子级超级视图设置了转换,但我认为您不得不在子视图中使用它。我尝试单独设置转换,并且转换的所有时间都搞砸了。在某些情况下,来自布伦特的上述情况也可能派上用场。

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.

这篇关于防止子视图在其超级视图变形时发生变形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆