在iOS 13上看不到InputAccessoryView

时间:2019-12-04 14:56:02

标签: ios ios13 uitoolbar inputaccessoryview inputview

在ViewController中,我添加了InputButton。我有用于从输入视图中选择值的自定义类。

class InputButton: UIButton {
    var customInputView: UIView = UIView()
    var customInputAccessoryView: UIView = UIView()

    override var inputView: UIView {
        get { return self.customInputView }
        set { self.customInputView = newValue }
    }
    override var inputAccessoryView: UIView {
        get { return self.customInputAccessoryView }
        set { self.customInputAccessoryView = newValue }
    }

    override var canBecomeFirstResponder: Bool {
        return self.isEnabled
    } 
}

点击按钮后,执行(在ViewController中):

self.currencyButton.inputView = self.currenciesPicker
self.currencyButton.inputAccessoryView = self.doneToolbar
self.currencyButton.becomeFirstResponder()

doneToolbar 是已设置的自定义UIToolbar

private lazy var spaceItem: UIBarButtonItem = {
    let item: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
    return item
}()
private lazy var doneItem: UIBarButtonItem = {
    let item: UIBarButtonItem = UIBarButtonItem(customView: self.doneButton)
    return item
}()

...

self.barStyle = UIBarStyle.default
self.items = [
    self.spaceItem,
    self.doneItem
]

大小是手动设置的,但我也尝试过用其他方式设置它。

this is result

我不知道为什么在iOS 13上inputAccessoryView 不可见可见,但是在iOS 12上它可以正常显示

debug view hierarchy中,inputAccessoryView看起来很好

0 个答案:

没有答案