iOS 11上的UIPickerView发生了变化吗?

4
在我们的应用程序中,我们有一个UIPickerView,让您选择一个季节。然而,在iOS 11上,“完成”按钮和“取消”按钮消失了,只有在切换应用程序时才可见。有其他人经历过这种情况吗?
附带iOS 11行为的截图,下面是iOS 10的行为。
编辑:这里有一个有问题的完整示例应用程序
这是设置选择器视图的代码。
func setUpPickerView(){

    self.seasonPicker = UIPickerView.init(frame: CGRect.init(x: 0, y: 50, width: self.frame.width, height: UIScreen.main.bounds.height / 3))
    self.seasonPicker.delegate = self
    self.seasonPicker.dataSource = self

    self.seasonTextField.inputView = self.seasonPicker

    let toolbar = UIToolbar.init(frame: CGRect.init(x: 0, y: 0, width: self.frame.width, height: 50))
    toolbar.barStyle = UIBarStyle.default

    let labelTitle = UILabel.init(frame: CGRect.init(x: 0, y: 50, width: 150, height: 20))
    labelTitle.backgroundColor = UIColor.clear
    labelTitle.textColor = UIColor.black
    labelTitle.textAlignment = NSTextAlignment.left
    labelTitle.text = "Select a Season"
    labelTitle.sizeToFit()

    let typeFeild = UIBarButtonItem.init(customView: labelTitle)
    let cancelButton = UIBarButtonItem.init(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(didClickPickerCancel))
    let flexSpace = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
    let doneButton = UIBarButtonItem.init(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(didClickPickerDone))
    toolbar.items = [cancelButton, flexSpace, typeFeild, flexSpace, doneButton]

    toolbar.sizeToFit()

    self.seasonTextField.inputAccessoryView = toolbar

}

UIPickerView with missing done button UIPickerView's done button reappears while switching between views UIPickerView working as expected on iOS 10


这些按钮不是选择器视图的一部分,我怀疑它们与它们无关。更可能的是,它与您呈现或布置显示所有内容的容器的方式有关。您应该发布创建该视图/控制器的代码。 - Dima
2个回答

10

事实证明,这个问题有一个简单的解决方法:

self.seasonPicker.translatesAutoresizingMaskIntoConstraints = false

从内部看,似乎他们已经更改了输入附件视图的行为,使其默认情况下具有此属性。


0

我之前使用了initWithFrame进行了分配,因此我进行了更改,如下:

   UIPickerView picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43, 320, 480)];

UIPickerView picker =  [UIPickerView new];

还有针对 UIToolbar 的操作

UIToolbar toolbar = [UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];

至于

UIToolbar toolbar = [UIToolbar new];

现在“完成”按钮已经可见了...问题是旧版的iOS 10只允许使用固定大小...现在最好的方法是为iOS 11进行优化。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接