Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

ios - UIAlertController change other UIView

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...