bringSubviewToFront problem?

前端 未结 2 895
醉话见心
醉话见心 2020-12-16 13:47

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

相关标签:
2条回答
  • 2020-12-16 14:15

    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];
    
    0 讨论(0)
  • 2020-12-16 14:23

    my contribution with the swift version from the checked solution

    self.bringSubviewToFront(self.grandchildview.superview!)
    self.grandchildview.superview!.bringSubviewToFront(self.grandchildview)
    
    0 讨论(0)
提交回复
热议问题