I have a problem with UITextField action. When I tap on it it is supposed to pop up a date picker view. The date picker piew popped up but I can't roll it or change the date. It seems like it is stuck. her is an image of my result the date Picker is freezes in November 16 2019
@IBAction func textFieldDidBegin(_ sender: Any)
{
let pickerView: UIDatePicker = {
let view = UIDatePicker()
view.layer.shadowColor = UIColor.rgb(5, 0, 0, 0.13).cgColor
view.layer.shadowRadius = 14
view.layer.shadowOffset = CGSize(width: 0, height: 9)
view.layer.shadowOpacity = 1
view.backgroundColor = .white
return view
}()
pickerView.timeZone = .current
pickerView.datePickerMode = UIDatePicker.Mode.date
view.addSubview(pickerView)
pickerView.centerInSuperview()
}
extension UIColor {
class func rgb(_ red: CGFloat, _ green: CGFloat, _ blue: CGFloat, _ alpha: CGFloat = 1) -> UIColor {
return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: alpha)
}
}
extension UIView {
func centerInSuperview() {
self.translatesAutoresizingMaskIntoConstraints = false
self.centerHorizontallyInSuperview()
self.centerVerticallyInSuperview()
}
func centerHorizontallyInSuperview(){
let c: NSLayoutConstraint = NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: self.superview, attribute: .centerX, multiplier: 1, constant: 0)
self.superview?.addConstraint(c)
}
func centerVerticallyInSuperview(){
let c: NSLayoutConstraint = NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: self.superview, attribute: .centerY, multiplier: 1, constant: 0)
self.superview?.addConstraint(c)
}
}
Also when I run the code from textFieldDidBegin into ViewDidLoad() function it's works fine .