我试图在我的视图控制器的顶部和底部显示一个 toast 视图。但是,“安全区域布局”指南既不包括导航栏,也不包括底部的标签栏。包括状态栏。我想在导航栏下方显示 toast 视图。
这是我的代码:
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)
])