如何在 UIDatePicker 中禁用无限滚动? [英] How to disable infinite scrolling in UIDatePicker?
问题描述
我正在实现一些带有日期选择的东西,结果证明 Apple 的 UIDatePicker 实现在数天和数月内使用无限循环.用简单的英语来说,不可能达到 1 的上限,也不可能达到 12 或 31 的底部.它只是永远循环,以 1 再次开始两组,依此类推,从我非常主观的角度来看,这是这个 UI 组件上最愚蠢的想法.
I am implementing something with a date selection and it turns out that Apple's implementation of UIDatePicker uses infinite loop for days and months. In plain english, it is impossible to hit a ceiling of 1 nor the bottom that is 12 or 31. It just loops forever starting both sets again with 1 and so on which is from my very subjective perspective the stupidest idea on this UI component.
此选择器的 UX 旋转速度非常快,因此实际上很难命中正确的数字.如果是 11 月,而我需要 2 月,那么使用 fast vert 达到顶峰会快得多.滑动,然后稍微向下移动到二月,在我在无限集合中找到二月之前,我宁愿这样做而不是一些不稳定的移动.
The UX with this picker is such that the speed of spinning is very fast so it is actually difficult to hit the right number. If it is november, and I need february, it would be much faster to just hit the top with fast vert. swipe, and then do a slight move down to Feb, which I would prefer over a few shaky moves until I find Feb in the infinite set.
查看类参考,我似乎找不到任何东西.也不是超类好像有合适的属性.
Looking at the class reference, I can't seem to find anything. Nor it's superclass seems to have a suitable property.
任何应用商店安全的想法(不包括自定义实现......作为最后的手段)?
Any appstore-safe ideas (exc. custom implementation..as a last resort)?
推荐答案
我曾经使用过以下来自另一个 stackoverflow 问题的代码,并且运行良好.
I have used this code below from another stackoverflow question in the past and works well.
如何设置最短时间每次都在 UIDatepicker 中显示为默认值
int startHour = 7;
int endHour = 11;
NSDate *date1 = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date1];
[components setHour: startHour];
[components setMinute: 0];
[components setSecond: 0];
NSDate *startDate = [gregorian dateFromComponents: components];
[components setHour: endHour];
[components setMinute: 0];
[components setSecond: 0];
NSDate *endDate = [gregorian dateFromComponents: components];
[userTimePicker setDatePickerMode:UIDatePickerModeTime];
[userTimePicker setMinimumDate:startDate];
[userTimePicker setMaximumDate:endDate];
[userTimePicker setDate:startDate animated:YES];
[userTimePicker reloadInputViews];
这篇关于如何在 UIDatePicker 中禁用无限滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!