1

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,...
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
  • As I understand it, you would like to change the view hierarchy across view controllers without adding a subview or altering the views on top of it? I don’t think that is possible because only sibling views may overlap each other. perhaps create a ‘merging’ dequeue cell and pass data from both delegates to it, it should be just as fast if latency is an issue. Just a suggestion, good luck! – RLoniello Nov 19 '17 at 18:57
  • Yes, this is pretty much what I would like to do. But what is then zPosition if it is not that? – Marko Zadravec Nov 19 '17 at 19:18
  • `zPosition`, at least as you've linked to, is for `SpriteKit` (it says so right at the top of your link). As such, working with two `UITableView`s won't work. –  Nov 19 '17 at 20:22
  • Sorry, I updated the link,.. – Marko Zadravec Nov 19 '17 at 20:27
  • I don't think this is possible. – dasdom Nov 19 '17 at 20:36

1 Answers1

3

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

self.myView.layer.zPosition = 1
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
Sandip Gill
  • 1,060
  • 1
  • 11
  • 22
  • This is not working. I already try this. I think the problem why this is not working is that both views, header1 and header2 doesn't have same parent view. (one have table1 and second have table2). I could be wrong, but then, please provide some more code, or example, where this is working. – Marko Zadravec Nov 20 '17 at 14:56
  • 1
    you are perfect! I needed to send a custom subview behind cell. The result is `bringSubviewToFront` and `sendSubviewToBack` don't work but `zPosition = -1` works perfect – Vyachaslav Gerchicov Apr 28 '21 at 06:37