0

I have my swift 5 app working and I'm now adding a 'tool tips' feature, explaining what each part of the screen does.

The approach I have taken is from an article online - add a subview of grey to dim the background, then to that, add a subview of the item being described again, so it is now highlighted, then also, add a subview of an explainer bubble to explain the item highlighted.

This works fine, so long as the UIView I'm using isn't from a UIBarButtonItem. When it is, the bar buttons underneath the grey screen move around to accomodate what they believe is another bar button being added, which causes everything to miss-align. Other buttons do not have this problem, only UIBarButtons.

Any advice is greatly appreciated. Thanks.

Matt Harg
  • 9
  • 3

1 Answers1

0

Are you adding the duplicate subview to the bar itself? It'd probably be better to add it to the screen rather than the bar so it doesn't affect the bar's layout. In order to get its frame relative to the view controller so you can display your duplicate in the correct position, you could use:

barButtonItem.convert(barButtonItem.bounds, to: self.view)

Assuming self is a UIViewController.

Miles
  • 487
  • 3
  • 12
  • Thanks for this. It gave me the idea to go up the superview's which works a lot better. I think ultimately using barButtons instead of UIBarButtonItems works best of all. – Matt Harg Sep 22 '21 at 19:36