I am using UIDatePickerStylepact to show a compact picker for selecting time:
let picker = UIDatePicker()
picker.preferredDatePickerStyle = pact
picker.datePickerMode = .time
picker.addTarget(self, action: #selector(startTimeChanged(sender:)), for: .valueChanged)
@objc func startTimeChanged(sender: UIDatePicker) {
//do something
}
This results in below picker:
This works well and the .valueChanged
lets me know when the time selection is changed.
However, is there also a way of knowing when the picker is dismissed (typically by tapping outside the picker view)? I tried using .touchUpOutside
but it isn't triggered when picker is dismissed. However, if I use .allEvents
, then my selector is called multiple times, including when dismissed, but I have no idea which event caused it.
I am using UIDatePickerStylepact to show a compact picker for selecting time:
let picker = UIDatePicker()
picker.preferredDatePickerStyle = pact
picker.datePickerMode = .time
picker.addTarget(self, action: #selector(startTimeChanged(sender:)), for: .valueChanged)
@objc func startTimeChanged(sender: UIDatePicker) {
//do something
}
This results in below picker:
This works well and the .valueChanged
lets me know when the time selection is changed.
However, is there also a way of knowing when the picker is dismissed (typically by tapping outside the picker view)? I tried using .touchUpOutside
but it isn't triggered when picker is dismissed. However, if I use .allEvents
, then my selector is called multiple times, including when dismissed, but I have no idea which event caused it.
1 Answer
Reset to default 0I figured it out. The event .editingDidEnd
calls my selector when the picker is dismissed.
picker.addTarget(self, action: #selector(dismissed(sender:)), for: .editingDidEnd)
@objc func dismissed(sender: UIDatePicker) {
//do rest
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744179502a4561914.html
评论列表(0条)