i spend lot of time but i can not figure out how can fix this problem . I made a picker view that is appearing from bottom . it is working fine but problem is when any other event shown alert view . same time picker view come from top .
note . before alert view appear . picker view working fine . after alert view appear then piker view come to the top .
bottom appear piker view code :
extension RegistrationController {
func showSettings(selecteIndex : Int) {
//show menu
if let window = UIApplication.shared.keyWindow {
blackView.backgroundColor = UIColor(white: 0, alpha: 0.5)
blackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleDismiss)))
window.addSubview(blackView)
window.addSubview(bottomView)
bottomView.addSubview(titlebottomView)
titlebottomView.addSubview(bottomViewActionLabel)
titlebottomView.addSubview(doneButton)
let height: CGFloat = 150
let y = window.frame.height - height
bottomView.frame = CGRect(x: 0, y: window.frame.height, width: window.frame.width, height: height)
titlebottomView.frame = CGRect(x: 0, y: 0, width: window.frame.width, height: 40)
bottomView.addSubview(pikerViewForGender)
bottomViewActionLabel.text = "Select your Gender"
bottomView.addSubview(pikerViewForGender)
pikerViewForGender.frame = CGRect(x: 0, y: 44, width: bottomView.frame.width, height: bottomView.frame.height - 40)
self.bottomViewActionLabel.frame = CGRect(x: 13, y: 0, width: 150, height: 40)
self.doneButton.frame = CGRect(x: window.frame.width - 80 , y: 0, width: 80, height: 40)
blackView.frame = window.frame
blackView.alpha = 0
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.blackView.alpha = 1
self.bottomView.frame = CGRect(x: 0, y: y, width: window.frame.width, height: height)
}, completion: nil)
}
}
func handleDismiss() {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.blackView.alpha = 0
if let window = UIApplication.shared.keyWindow {
self.bottomView.frame = CGRect(x: 0, y: window.frame.height, width: window.frame.width, height: window.frame.height)
}
}) { (completed: Bool) in
print("good way ....")
}
}
}
alert view code :
extension UIViewController {
func showAlert(message: String ){
let alert = UIAlertController(title: "Whoops", message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {(_ action: UIAlertAction) -> Void in
alert.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
}
}
See Question&Answers more detail:
os