How can I animate displaying UIPickerView after pressing button?

后端 未结 6 1311
日久生厌
日久生厌 2021-02-03 13:38

I want to animate my UIPickerView after pressing the button. I already have coded my UIPickerView to be hidden on viewDidLoad and not hidden after pressing a button, but it does

6条回答
  •  清酒与你
    2021-02-03 13:43

    Swift 5: Slide up animation

    1- Set hight to 216 (PickerView Standard).

    2- Set leading an trailing to safe Area.

    3- Set Bottom to "SuperViewBottom" as -216.

    4- Make a IBOutlet from line 3 as NSLayoutConstraint optional.

    and then:

    import UIKit
    
    class ViewController: UIViewController {
    
     override func viewDidLoad() {
    
     super.viewDidLoad()
    
     bottom.constant = -216
    
    }
    
    @IBOutlet weak var bottom: NSLayoutConstraint!
    
    -(IBAction)button:(id)sender
    {
       UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations:
            {
                self.bottom.constant = 0
            self.view.layoutIfNeeded()
            }) { (AnimationComplete ) in }
    }
    
     override func touchesBegan(_ touches: Set, with event: UIEvent?) {
           
    
            UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations:
            {
                self.bottom.constant = -216
            self.view.layoutIfNeeded()
            }) { (AnimationComplete ) in }
       
        }
    
    
    }
    
    

    it should working like Apple standard animation.

    Good luck

提交回复
热议问题