custom inputAccessoryView as UIView from nib giving error: returned 0 width, assuming UIViewNoIntrinsicMetric
Asked Answered
M

0

15

I am using an inputAccessoryView which is loaded from a nib using the following UIView subclass:

class CustomInputAccessoryView: UIView {

    @IBOutlet var containerView: UIView!
    @IBOutlet var contentView: UIView!
    @IBOutlet weak var button1: UIButton!
    @IBOutlet weak var button2: UIButton!
    @IBOutlet weak var textView: UITextView!        

    override var intrinsicContentSize: CGSize {
        return CGSize.zero
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupInputAccessoryView()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupInputAccessoryView()
    }

    func setupInputAccessoryView() {
        self.translatesAutoresizingMaskIntoConstraints = false
        Bundle.main.loadNibNamed("CustomInputAccessoryView", owner: self, options: nil)
        addSubview(containerView)
        containerView.frame = self.bounds
    }

}

I assign the view to the inputAccessoryView and set it up just by the following:

var customInputAccessoryView = CustomInputAccessoryView()

The inputAccessoryView loads properly and displays correctly. The problem is when I press inside the textView of the inputAccessoryView and the keyboard displays, I get the following error:

<_UIKBCompatInputView: ...; frame = (0 0; 0 0); layer = <CALayer: ...>> returned 0 width, assuming UIViewNoIntrinsicMetric

I have two files, a .swift file which is the subclass of UIView displayed above and the nib file by the same name. In the file owner of the nib I select the sub class (CustomInputAccessoryView) and wire up the outlets.

I don't really know what is happening other than maybe the input accessory view automatically resizing to zero frame whenever the keyboard is displayed before going to the correct size. If so I'm assuming I need to change some AutoLayout priorities but what I have tried is not working. The only hard width constraints are the buttons which have fixed widths.

The inputAccessoryView width should always be the width of the window it is displayed in.

Mensural answered 29/5, 2018 at 9:38 Comment(1)
Did you ever find a solution to this?Macymad

© 2022 - 2024 — McMap. All rights reserved.