2017-09-19 67 views
1

我我的項目更新爲我有一個inputText的使用選擇器 白衣一個輸入視圖我在inputText的添加了一個UIToolBar。 它在升級前運行良好。 現在它就像UIPickerView它超過了UIToolBarUiPickerView過UiToolBar - 斯威夫特4升級錯誤

我可以看到,但如果我點擊它就像我點擊UIPickerView

UIToolBar這是完全的工作,因爲如果我的工具欄設置爲普通的TextInput它看起來和工作以及..

什麼可?

這裏是我的代碼:

var picker: UIPickerView 
picker = UIPickerView(frame: CGRect(x: 0, y: 200, width: view.frame.width, height: 300)) 
picker.backgroundColor = .white 

picker.showsSelectionIndicator = true 
picker.delegate = self 
picker.dataSource = PickerData as? UIPickerViewDataSource 


textField.inputView = picker 

let toolBar = UIToolbar() 
toolBar.barStyle = UIBarStyle.default 
toolBar.isTranslucent = true 
toolBar.tintColor = .blue 
toolBar.sizeToFit() 

let doneButton = UIBarButtonItem(title: "Seleziona", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.doneFunction(_:))) 
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil) 
let cancelButton = UIBarButtonItem(title: "Annulla", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.doneFunction(_:))) 

toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false) 
toolBar.isUserInteractionEnabled = true 

textField.inputAccessoryView = toolBar 

我也picker.addSubview(toolBar)但絲毫同樣的結果嘗試。

回答

0

我有同樣的問題,我解決了它與背景視圖和添加2個子視圖 - 選擇器和工具欄。 下面是代碼:

let toolBar = UIToolbar() 
    toolBar.barStyle = UIBarStyle.default 
    toolBar.isTranslucent = true 
    toolBar.tintColor = green 
    toolBar.sizeToFit() 

    picker = UIPickerView(frame: CGRect(x: 0, y: toolBar.frame.size.height, width: view.frame.width, height: 300)) 
    picker.tintColor = green 
    picker.showsSelectionIndicator = true 
    picker.delegate = self 
    picker.dataSource = self 

    let bgView = UIView(frame: CGRect(x: 0, y: 200, width: view.frame.width, height: 300 + toolBar.frame.size.height)) 

    let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(nextPicker)) 
    let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil) 
    let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelPicker)) 
    toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false) 
    toolBar.isUserInteractionEnabled = true 

    bgView.addSubview(picker) 
    bgView.addSubview(toolBar) 
    cell.textField.inputView = bgView 

希望它幫助。

+0

感謝它的完美工作 – Piedecess