在我們的應用程序中,我們有一個UIPickerView,可以讓您選擇一個季節。但是,在iOS 11上,完成按鈕和取消按鈕消失並且僅在應用程序之間切換時可見。有沒有其他人經歷過這個?UIPickerView在iOS 11上更改?
iOS 11行爲的屏幕截圖,下面有iOS 10行爲。
編輯:下面是該問題一個complete sample app:
下面是設置選擇器視圖
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
}
那些按鈕都沒有選擇器視圖的一部分,最好的辦法我懷疑這與他們有什麼關係。更有可能的是,它與你展示或展示你所展示的容器的方式有關。你應該發佈創建該視圖/控制器的代碼。 – Dima