1

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. i found following solution inputAccessoryView Iphone X

after following idea from above link i can place my textfield above the layout guid but it become unresponsive. which is happening because there is no frame size define for view of 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

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.

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.

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. sample image

let me know if you do not understand. please help thank you in advance.

deepak
  • 13
  • 4
  • 10

1 Answers1

1

Try adding a top anchor to your '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.

Landon Tetreault
  • 115
  • 1
  • 10
  • it kind of work but the inputContainerView is Squeezed check this image [link](https://ibb.co/jC6T8H). how do i increase size of the InputAccessoryView? – deepak Mar 01 '18 at 05:29
  • i tried to increase the font size of inputTextField but still the size of inputAccessoryView is same. thanx for the help @Landon – deepak Mar 01 '18 at 05:31
  • 1
    working fine problem is solved. the button was squeezed because i was using UIImageView and the contentMode Propery was not set thats why the plus icon was squeezed. – deepak Mar 01 '18 at 08:38