iqra
iqra

Reputation: 1251

UIApplication key window 'safe area layout guide" excludes tab bar & navigation bar

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)
])

Upvotes: 1

Views: 327

Answers (0)

Related Questions