iOS Different behavior when tapping UIDatePicker

Viewed 39

Good afternoon,

I have detected a difference with UIDatePicker's behaviour:

My UIDatePicker setup (Only time)

let timePicker: UIDatePicker = {
    let view = UIDatePicker()
    view.translatesAutoresizingMaskIntoConstraints = false
    view.datePickerMode = .time
    if #available(iOS 13.4, *) {
        view.preferredDatePickerStyle = .wheels
    }
    return view
}()

On the simulator (iPhone SE - 2nd generation - iOS 15.2) I can tap on the time slider and a keyboard appears, allowing me to enter a time. But when testing on my phone (iPhone SE - 1st generation - iOS 14.7.1) this behaviour doesn't work (when I tap nothing happens, no keyboard, no input).

Is possible to enable this when using my phone ?

Also I have a date picker (only date)

let datePicker: UIDatePicker = {
    let view = UIDatePicker()
    view.translatesAutoresizingMaskIntoConstraints = false
    view.datePickerMode = .date
    if #available(iOS 13.4, *) {
        view.preferredDatePickerStyle = .wheels
    }
    return view
}()

The tap actions doesn't work in simulator or on the phone. Is there a way to activate it ? (So it's easier to quickly enter a year)

How I add and lay the datepickers

I add them in the init of UIStackview

init() {
    super.init(frame: CGRect.zero)

    translatesAutoresizingMaskIntoConstraints = false

    axis = .vertical
    alignment = .center
    distribution = .equalSpacing

    addArrangedSubview(datePicker)
    datePicker.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
    datePicker.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
    datePicker.heightAnchor.constraint(equalToConstant: 50).isActive = true

    addArrangedSubview(timePicker)
    timePicker.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
    timePicker.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
    timePicker.heightAnchor.constraint(equalToConstant: 50).isActive = true
}

Thanks for your time.

0 Answers
Related