0

Hopefully this isn't too confusing.

I have a main view controller (MainView) with a stackview at the bottom of the view and inside the stackview I have three views. Inside one the views (lets call it footerView) i'm adding a little tooltipView - and because footerView is nestled inside a stackview at the bottom of MainView - it's got some overlap with the other views. I want to tell the tooltipView to be on top of all the views but it's not working. Inside footerView - it has no superview (I presume because it's inside a stackview) so I can't use parentView.bringSubviewToFront(childView).

What could I do instead? Is delegation through the layers the only way?

vanilla_splsh
  • 153
  • 1
  • 12

2 Answers2

2

You can manually set the zPosition of each layer. The default value is 0 so you may not get the desired value you want without manually controlling it. As an example you could try

tooltipView.layer.zPosition = 1

or

tooltipView.layer.zPosition = .greatestFiniteMagnitude

Setting it to 1 will make it above other views that default to 0 or setting it to .greatestFiniteMagnitude will always have it at the front.

Check out this answer on zPostion and Apple's documentation on zPostion.

Tommy
  • 115
  • 1
  • 10
0

Tommy's answer did help but another thing that helped was that I was creating my tooltipView before footerView had finished being set up - hence why the superview was nil. I moved the initialisation of tooltipView to be inside func layoutSubviews() and it works.

But ALSO make sure you untick clip to bounds. This is why no matter what i did with zPosition made no difference

vanilla_splsh
  • 153
  • 1
  • 12