iOS9: UIDatePicker with datePickerMode of UIDatePickerModeTime 只显示小时,没有分钟

iOS9: UIDatePicker with datePickerMode of UIDatePickerModeTime only shows Hours, and no Minutes

我正在使用 Xcode beta 7 和 iOS9 模拟器。 使用具有 UIDatePickerModeTime 的 datePickerMode 的 UIDatePicker 仅显示小时,而不是分钟。

见截图:

在 iOS 7 和 8 上,显然它按预期工作,并显示小时和分钟。截图:

我真的不想重新发明轮子并推出自己的时间选择器。关于为什么会发生这种情况以及如何解决的任何想法?我在 google 上找不到任何内容。

谢谢, 亚历克斯

我在 public 版本 iOS 9.0 的 public 版本之后遇到了这个问题,在我的表视图中使用 UIDatePickerModeDate 的 UIDatePicker。

我通过在它显示之前更改 UIDatePicker 模式来绕过它,然后将其更改回所需的模式:

[myDatePicker setDatePickerMode:UIDatePickerModeDateAndTime];
[myDatePicker setDatePickerMode:UIDatePickerModeDate];

我猜重绘它可以解决问题。为了兴趣起见,我认为这实际上不是不显示会议记录的问题,而是子视图中的错误,因为这是我的样子:

正在使用 FLEX 检查,这是具有纯白色背景的 UIDatePicker 的一部分。

@LordParsley 解决方案成功了。

只是一些额外的细节:

我注意到它出现在 iPhone 5 系列而不是 iPhone 6/6 plus 上,带有前导和尾随约束。 显然只有当帧宽度为 320 时才会出现错误。可能是选择器子视图的错误计算导致了重叠。这很有趣,因为 Apple 是设置默认值的人,但他们已经监督了这个问题。

无论如何,我希望这个问题可以通过现在处于测试阶段的 iOS 9.1 得到解决。

我在 运行 我的应用程序 iOS 9 时遇到同样的问题,我的应用程序在 .xib 文件中使用 UIDatePicker。 我通过在后面的代码中添加它解决了这个问题:

UIDatePicker* picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 44, 320, 162)];
[self.view addSubview:picker];

我认为,这是新字体 San Francisco(字体比 Helvetica 大)和 .xib 文件的问题。 希望这有帮助。 谢谢!

我在将 Xcode 升级到 7.0 时遇到问题。

根据 LordParsley 的回答,显示 UIDatePicker 时中间部分是空白的。

iOS9的UIDatePicker高度为216;而早期版本的高度是 162,强制高度为 162 解决了这个问题。

由于我的视图是在情节提要中定义的,因此我在 UIDatePicker 上设置了一个高度约束,并将 iOS 版本 < 9.0 的高度设置为 162,在视图的 viewDidLoad 中。

- (void) viewDidLoad {
    [super viewDidLoad];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
        //
        // NOTE: iOS 9, or Xcode 7, now sets UIDatePicker height at 216; whereas,
        // iOS 8, or Xcode 6.x, set it at 162.
        //
        // If the height is left at 216, then on iOS 7.1, the middle portion of the
        // UIDatePicker control is missing.  Setting the hieght to 162 fixes the issue
        // within this application.
        //
        // UIDatePicker frame cannot be used to adjust the size, therefore use a
        // height contraint to change the size.
        //
        self.dateHeightConstraint.constant = 162;
    }
}

在 iOS 9 发行说明中找到了有关此问题的有用描述 - 看来我应该更仔细地阅读这些内容。

UIPickerView and UIDatePicker are now resizable and adaptive—previously, these views would enforce a default size even if you attempted to resize them. These views also now default to a width of 320 points on all devices, instead of to the device width on iPhone. Interfaces that rely on the old enforcement of the default size will likely look wrong when compiled for iOS 9. Any problems encountered can be resolved by fully constraining or sizing picker views to the desired size instead of relying on implicit behavior.

iOS 9 Release Notes

在我的例子中,我所要做的就是删除 UIDatePicker 上的所有约束,然后 "Reset to Suggested Constraints"。重建,现在一切都很好。

On iPhone 5S iOS 9.1 当我显示 UIDatePicker 时,我的月份名称被截断了。我通过如下设置本地 属性 解决了这个问题:

NSLocale *uk = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setLocale:uk];
[_backdateDatePicker setCalendar:cal];