Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 .

here before alert

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 ....")

        }
    }

}

when showing alert

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
201 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your done button is added as subview onto titlebottomView. When you see your done button up there, it means that your titlebottomView is still on your screen, not getting dismissed or brought back. So in your handleDismiss() function, use your desired way to make sure titlebottomView is in some off screen location or bring it back as best practice.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...