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 缺少完成按钮 UIPickerView 的完成按钮在视图之间切换时重新出现 UIPickerView 在 iOS 10 上按预期工作

4

2 回答 2

10

原来有一个简单的解决方法:

self.seasonPicker.translatesAutoresizingMaskIntoConstraints = false

在内部,看起来他们已将输入附件视图的行为更改为默认启用此属性。

于 2017-06-09T20:12:56.387 回答
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 的最佳方式

于 2017-11-21T09:07:38.200 回答