[英]inputAccessoryView with intrinsicContentSize in iphone x not working
please do not down vote will try my best to explain problem. 请不要拒绝投票,我会尽力解释问题。
i have an InputAccessoryView which was working fine before iphone x, in iphone x my inputAssesoryView is showing at very bottom below the layoutguide. 我有一个InputAccessoryView,在iPhone X之前运行良好,在iPhone X中,inputAssesoryView显示在布局指南下方的最下方。 i found following solution inputAccessoryView Iphone X 我发现以下解决方案inputAccessoryView Iphone X
after following idea from above link i can place my textfield above the layout guid but it become unresponsive. 从上面的链接遵循以下想法之后,我可以将我的文本字段放置在布局guid上方,但是它没有响应。 which is happening because there is no frame size define for view of inputAccessoryView. 之所以发生这种情况,是因为没有为inputAccessoryView的视图定义帧大小。
class ChatInputContainerView: UIView, UITextFieldDelegate {
override var intrinsicContentSize: CGSize {
return CGSize.zero
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
lazy var inputTextField: UITextField = {
let textField = UITextField()
textField.placeholder = "Enter message..."
textField.translatesAutoresizingMaskIntoConstraints = false
textField.delegate = self
return textField
}()
override init(frame: CGRect) {
super.init(frame: frame)
autoresizingMask = .flexibleHeight
self.inputTextField.leftAnchor.constraint(equalTo: rightAnchor, constant: 8).isActive = true
self.inputTextField.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
self.inputTextField.rightAnchor.constraint(equalTo: leftAnchor).isActive = true
self.inputTextField.heightAnchor.constraint(equalTo: heightAnchor).isActive = true
}
}
following is controller where i am using inputAccessory View 以下是我正在使用inputAccessory视图的控制器
class chatController: UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
lazy var inputContainerView: ChatInputContainerView = {
// let chatInputContainerView = ChatInputContainerView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 50))
let chatInputContainerView = ChatInputContainerView()
chatInputContainerView.chatLogController = self
return chatInputContainerView
}()
override var inputAccessoryView: UIView? {
get {
return inputContainerView
}
}
override var canBecomeFirstResponder : Bool {
return true
}
}
previously i was using following code to get size of InputAccessoryView which place the view at the bottom with fix height. 以前我使用下面的代码来获取InputAccessoryView的大小,该视图将视图固定在底部。
let chatInputContainerView = ChatInputContainerView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 50))
but now i am using following to set inputAccessoryView which is not working properly, textfield inside view become unresponsive because parent view have no size define. 但是现在我正在使用以下方法来设置不能正常工作的inputAccessoryView,由于父视图没有定义大小,视图内部的文本字段变得无响应。
override var intrinsicContentSize: CGSize {
return CGSize.zero
}
autoresizingMask = .flexibleHeight
in following image you can see all my control are now above the safeAreaLayout but they become unresponsive. 在下图中,您可以看到我所有的控件现在都在safeAreaLayout上方,但它们没有响应。 sample image 样本图片
let me know if you do not understand. 如果您不明白,请告诉我。 please help thank you in advance. 请提前帮助您。
Try adding a top anchor to your 'inputTextField' 尝试在“ inputTextField”中添加顶部锚点
self.inputTextField.topAnchor.constraint(equalTo: topAnchor).isActive = true
I might be wrong but without knowing where the top is the 'ChatInputContainerView' will have zero height. 我可能是错的,但不知道顶部的'ChatInputContainerView'高度为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.