Bring view to front even if it not in right hierarchy order

1.1k Views Asked by At

I know that "how to bring view to front", was asked many time, and I don't look for another :

self.bringSubview(toFront: myView)

My problem why this is not working is, that I have different hierarchical structure.

I have UIView on witch I add UITableView (first one), and then another UITableView (second one) on top.

Why I have two UITableView on top of each other is not important for this discussion, let just say, it need to be like that.

I have two headers, one from first and second table view. Now I would like to bring label from first table view header to front. (So that will not be blocked by second table view header)

    first header view
   --------------------------------------
   |                     first label    |
 -------------------------------------  |
 |                                   |  |
 |  Second label                     |---
 |                                   |
 -------------------------------------
  second header view

So in my little sketch, I need to bring first label on front.

I was looking at zPosition, and it sounds right, but I couldn't make it work.

To not get some useless answers, there is a list of options that is not solution for me :

  • Not to have one table behind another - I need this arrangement.

  • Bring first table to front : There is a reason that this table is behind (because of cells display)

  • Make second header view background opaque - Then rows, that go beneath header view will mess with header title.
  • Make first label on second header view - I need to be first label on first header view (only displayed on front) because of movement of cells, animations,...
1

There are 1 best solutions below

2
Sandip Gill On

Hello you can set zposition to 1 it will bring you view to front.

self.myView.layer.zPosition = 1