16

嗨,我有 Parentview-->Multiple childviews。当我在 parentview 中使用 [self bringSubviewToFront:childview] 时,它工作正常。但是在将 grandchildview 添加到 childview 之后,当我在 parentview 中使用 [self bringSubviewToFront: grandchildview] 时,它不起作用?请帮忙?

4

2 回答 2

65

-[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];
于 2010-09-22T06:39:34.327 回答
1

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

self.bringSubviewToFront(self.grandchildview.superview!)
self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)
于 2016-02-16T08:54:40.040 回答