带来SubviewToFront问题?

发布于 2024-09-24 06:45:19 字数 170 浏览 9 评论 0原文

你好, 我有父视图-->多个子视图。 当我在父视图中使用 [self BringSubviewToFront:childview] 时,它工作正常。但是在将孙子视图添加到子视图之后,当我使用 [self BringSubviewToFront: grandchildview] 在父视图中,它不起作用?有什么帮助吗?

HI,
I have Parentview-->Multiple childviews.
when i use [self bringSubviewToFront:childview] in parentview, it works fine.but after adding grandchildview to childview,when i use
[self bringSubviewToFront: grandchildview] in parentview, it did not work?any help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的影子我的梦 2024-10-01 06:45:19

-[UIView BringSubviewToFront:] 方法仅适用于直接子级,不适用于孙级。请记住,视图层次结构是一棵树,通常视图只知道其“父视图”(或超级视图)及其直接“子视图”(或子视图)。你需要做这样的事情:

// First, get the view embedding the grandchildview to front.
[self bringSubviewToFront:[grandchildview superview]];
// Now, inside that container view, get the "grandchildview" to front. 
[[grandchildview superview] bringSubviewToFront:grandchildview];

The -[UIView bringSubviewToFront:] method only works for direct children, not grandchildren. Remember that the view hierarchy is a tree, and normally a view only knows about its "parent" (or superview) and its direct "children" (or subviews). You would need to do something like this:

// First, get the view embedding the grandchildview to front.
[self bringSubviewToFront:[grandchildview superview]];
// Now, inside that container view, get the "grandchildview" to front. 
[[grandchildview superview] bringSubviewToFront:grandchildview];
于我来说 2024-10-01 06:45:19

我对已检查解决方案的 swift 版本的贡献

self.bringSubviewToFront(self.grandchildview.superview!)
self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)

my contribution with the swift version from the checked solution

self.bringSubviewToFront(self.grandchildview.superview!)
self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文