I have problem with interaction within my view that was loaded programatically. When app’s running the view is displayed well, however all input fields are not responsible.
Here is code of my view(file's owner - CarView):
CarView.swift - @IBDesignable class CarView: UIView {
@IBOutlet var myView: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
private func commonInit(){
Bundle.main.loadNibNamed("CarView", owner: self, options: nil)
self.bounds = self.myView.bounds
myView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
addSubview(myView)
} }
var carView : CarView = CarView()
@IBAction func carViewButton(_ sender: Any) {
view.addSubview(carView)
carView.translatesAutoresizingMaskIntoConstraints = false
carView.topAnchor.constraint(equalTo: carButton.bottomAnchor, constant: 10).isActive = true
carView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 8).isActive = true
carView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 8).isActive = true
}