1

I am trying to showing a toast view on top and bottom of my view controller. However, the "Safe Area Layout" guide is neither including the navigation bar or the tab bar at the bottom. The status bar is included. I want to show the toast view below my navigation bar.

Nav bar not included in safe area

Here's my code:

guard let rootView = UIApplication.shared.windows.filter({$0.isKeyWindow}).first else {return}
        

let toastView = ToastView(title: title, message: message, type: type)
toastView.translatesAutoresizingMaskIntoConstraints = false

rootView.addSubview(toastView)

NSLayoutConstraint.activate([
                    toastView.centerXAnchor.constraint(equalTo: rootView.centerXAnchor),
                    toastView.leadingAnchor.constraint(greaterThanOrEqualTo: rootView.leadingAnchor, constant: 20),
                    toastView.topAnchor.constraint(equalTo: rootView.safeAreaLayoutGuide.topAnchor, constant: 0)
])
iqra
  • 1,061
  • 1
  • 11
  • 18
  • The window is not where the safe area from the navigation controller or tab bar controller is imposed. The window is _above_ those controllers in the hierarchy. They impose the safe area _downwards_ in the hierarchy. – matt Dec 02 '20 at 20:23
  • So instead of using the window, use the window's root view controller's view and see if that works better. – matt Dec 02 '20 at 20:28

0 Answers0