I wish to present toast backside of display screen however, When keypad seems it’s hiding. Please anybody recommend me to unravel. Thanks you.
Under is the code i’m making an attempt.
func displayToast(_ message : String) {
guard let delegate = UIApplication.shared.delegate as? AppDelegate, let window = delegate.window else {
return
}
if let toast = window.subviews.first(the place: { $0 is UILabel && $0.tag == -1001 }) {
toast.removeFromSuperview()
}
let toastView = UILabel()
toastView.backgroundColor = UIColor.black.withAlphaComponent(0.7)
toastView.textColor = UIColor.white
toastView.textAlignment = .middle
toastView.font = UIFont(title: "Font-name", dimension: 17)
toastView.layer.cornerRadius = 15
toastView.clipsToBounds = true
toastView.textual content = message
toastView.numberOfLines = 0
toastView.alpha = 0
toastView.translatesAutoresizingMaskIntoConstraints = false
toastView.tag = -1001
let windowww = UIApplication.shared.home windows[UIApplication.shared.windows.count - 1]
windowww.addSubview(toastView)
let horizontalCenterContraint: NSLayoutConstraint = NSLayoutConstraint(merchandise: toastView, attribute: .centerX, relatedBy: .equal, toItem: windowww, attribute: .centerX, multiplier: 1, fixed: 0)
let widthContraint: NSLayoutConstraint = NSLayoutConstraint(merchandise: toastView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1, fixed: (self.body.dimension.width-25) )
let verticalContraint: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "V:|-(>=200)-[toastView(==50)]-68-|", choices: [.alignAllCenterX, .alignAllCenterY], metrics: nil, views: ["toastView": toastView])
NSLayoutConstraint.activate([horizontalCenterContraint, widthContraint])
NSLayoutConstraint.activate(verticalContraint)
UIView.animate(withDuration: 0.5, delay: 0, choices: .curveEaseIn, animations: {
toastView.alpha = 1
}, completion: nil)
DispatchQueue.most important.asyncAfter(deadline: .now() + .seconds(3), execute: {
UIView.animate(withDuration: 0.5, delay: 0, choices: .curveEaseIn, animations: {
toastView.alpha = 0
}, completion: { completed in
toastView.removeFromSuperview()
})
})
}