简体   繁体   English

重新定位UIView,使其子视图位置保持不变

[英]Reposition UIView keeping its subview position unchanged

How to reposition UIView keeping its subview at same position before reposition. 如何重新定位UIView,然后再将其子视图保持在相同位置。 When i move the UIView its subview are also getting moved.How can i avoid that. 当我移动UIView时,它的子视图也被移动了。我该如何避免这种情况。 I just want to move the parent view not its subviews. 我只想移动父视图而不是其子视图。

Since that's not how view hierarchy works, unless I am mistaken, there's no way to prevent a subview from moving with its superview. 既然这不是视图层次结构的工作原理,除非我弄错了,否则无法阻止子视图随其父视图一起移动。

What you could do is reposition the subview while the superview is moving (but don't animate it) so it gives the illusion that it doesn't move. 您可以做的是在父视图移动时重新定位子视图(但不对其进行动画处理),从而产生不移动的错觉。

The way I'd do it within these restrictions is to get the position of the subview in relation to the superview's superview (convertRect:toView: method) then simply set the frame's origin every time your superview is moving. 在这些限制内,我要做的方法是获取子视图相对于超级视图的超级视图的位置(convertRect:toView:方法),然后在每次超级视图移动时简单地设置框架的原点。

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

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