我添加了一个自定义inputAccessoryView
,其中包含一个子类UITextView
。
当我点击inputAccessoryView
时,键盘将其向上推,并显示以下2条警告:
API错误:<_UIKBCompatInputView:0x7f92815391b0;框架=(0 0; 0 0);层=>返回0宽度,假设UIViewNoIntrinsicMetric
API错误:<_UIKBCompatInputView:0x7f92815391b0;框架=(0 0; 0 0);层=>返回0宽度,假设UIViewNoIntrinsicMetric
当我在视图控制器上移动空的collectionView
时,键盘会随着inputAccessoryView
移回到屏幕底部而下降,然后显示另外2条警告:
[View]第一响应者警告:“ TextInputView:0x7f9282847000; baseClass = UITextView;框架=(10 10; 354 27);文字=''; clipsToBounds = YES; poseRecognizers =;层=; contentOffset:{0,3}; contentSize:{158.5,30.5}; AdjustedContentInset:{0,0,14,0}>'在从层次结构中删除时拒绝resignFirstResponder
-[UIWindow endDisablingInterfaceAutorotationAnimated:]在不匹配-beginDisablingInterfaceAutorotation的情况下调用。忽略。
是什么原因导致这些警告,以及如何防止它们出现?我在这里查找了类似的问题,但没有一个明确的答案。
根据要求,inputAccessoryView
:
class BigInputBar: UIView, UITextViewDelegate {
// MARK: - Subviews
let separatorLine = SeparatorLine()
// View that contains everything
var backgroundView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
lazy var inputTextView: TextInputView = {
let textView = TextInputView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.backgroundColor = .clear
return textView
}()
var sendButton: UIButton = {
let button = UIButton(frame: .zero)
let image = UIImage.getImage(named: "chevron-right")
button.setImage(image, for: [])
button.addTarget(self, action: #selector(sendButtonTapped), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
button.setBackgroundImage(image, for: .highlighted) //Fun develop only graphic
button.backgroundColor = .clear
button.isEnabled = false
return button
}()
@objc private func sendButtonTapped(){
print("Button Tapped")
}
// MARK: Properties
override var intrinsicContentSize: CGSize {
return CGSize(width: bounds.width, height: 60)
}
// MARK: - Init Methods
convenience init() {
self.init(frame: .zero)
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup() {
autoresizingMask = [.flexibleHeight]
addSubview(backgroundView)
addSubview(separatorLine)
backgroundView.addSubview(sendButton)
backgroundView.addSubview(inputTextView)
setupConstraints()
inputTextView.delegate = self
}
private func setupConstraints() {
separatorLine.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 0).isActive = true
separatorLine.rightAnchor.constraint(equalTo: self.rightAnchor, constant: 0).isActive = true
separatorLine.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true
backgroundView.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 0).isActive = true
backgroundView.rightAnchor.constraint(equalTo: self.rightAnchor, constant: 0).isActive = true
backgroundView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true
backgroundView.topAnchor.constraint(equalTo: separatorLine.bottomAnchor, constant: 0).isActive = true
sendButton.rightAnchor.constraint(equalTo: backgroundView.rightAnchor, constant: -10).isActive = true
sendButton.topAnchor.constraint(equalTo: backgroundView.topAnchor,constant: 10).isActive = true
sendButton.widthAnchor.constraint(equalToConstant: 30).isActive = true
sendButton.heightAnchor.constraint(equalToConstant: 30).isActive = true
let leftTextView = inputTextView.leftAnchor.constraint(equalTo: backgroundView.leftAnchor, constant: 10)
let rightTextView = inputTextView.rightAnchor.constraint(equalTo: sendButton.leftAnchor, constant: -10)
let bottomTextView = inputTextView.bottomAnchor.constraint(equalTo: backgroundView.bottomAnchor, constant: -20)
let topTextView = inputTextView.topAnchor.constraint(equalTo: backgroundView.topAnchor,constant: 10)
NSLayoutConstraint.activate([leftTextView, rightTextView, bottomTextView, topTextView])
}
}