UIPickerView changed to iOS 11?

In our application, we have a UIPickerView that allows you to select a season. However, on iOS 11, the Finish button and the Cancel button disappear and are visible only when switching between applications. Has anyone else experienced this?

Screenshots of iOS 11 behavior with iOS 10 behavior below.

Edit: here is the full sample application with the problem:

Here is the code to customize the selection view

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 a missing button The repeated UIPickerView button appears when switching between views. UIPickerView works as expected on iOS 10

+4
source share
2 answers

The simple fix brings up here:

self.seasonPicker.translatesAutoresizingMaskIntoConstraints = false

Inside, they seem to have changed the behavior of representations of auxiliary input devices to enable this property by default.

+9

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)];

to

UIToolbar toolbar = [UIToolbar new];

Done ... iOS 10 ... iOS 11

0

Source: https://habr.com/ru/post/1678891/


All Articles