我在旋转任何其他 View 后遇到 inputAccessoryView
问题。例如:
1)转到 View A并旋转到横向
2) 然后旋转回纵向。
3) 去查看B
在 View B 中,我有以下代码将 inputAccessoryView
分配给 UITextField
但是,在我旋转应用程序中的任何 View 后,附件 View 始终附加到顶部屏幕的顶部,而不是键盘的顶部。如果我不旋转任何 View ,附件 View 将按预期附加到键盘顶部。
这里是用于创建和分配inputAccessoryView
的代码,它是从viewDidLoad
func addDoneButtonOnKeyboard(){
let doneToolbar = UIToolbar(frame: CGRect(x:0, y:0, width:320, height:50))
doneToolbar.barStyle = UIBarStyle.blackTranslucent
doneToolbar.isTranslucent = true
let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace,
target: nil,
action: nil)
let doneButton = UIBarButtonItem(title: "Done",
style: UIBarButtonItemStyle.done,
target: self,
action: #selector(MyVC.doneButtonAction))
doneToolbar.setItems([flexSpace,doneButton], animated: false)
doneToolbar.sizeToFit()
doneToolbar.autoresizingMask=UIViewAutoresizing.flexibleWidth
self.myTextFild.inputAccessoryView = doneToolbar
}
我搜索过 SO 但没有看到任何其他类似的问题/答案....
最佳答案
我的情况是 inputView 是一个 datePicker,我遇到了同样的问题。我的解决方案是:
textFieldDate.inputView?.autoresizingMask = [.flexibleHeight, .flexibleWidth]
不确定这是否对您也有帮助,因为您正在使用键盘作为 inputView,但也许它可以帮助其他人解决 datePicker 问题。
关于ios - 旋转后 Swift inputAccessoryView 未连接到键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42030999/