Scene Dock View with VFL constraints not showing up

59 Views Asked by At

I have a View Controller that has a UIView (named pickerView) placed within the Scene Dock. The reason I am using the Scene Dock is this UIView will contain many child views, and I don't want to clutter up the storyboard. I am using VFL to size this pickerView, so that it's the full screen of the device.

The problem is, when I press openPickerButtonPressed, the yellow pickerView never shows up. Am I missing something here? Are the VFL constraints set up properly?

override func viewDidLoad() {
    super.viewDidLoad()
    self.pickerView.translatesAutoresizingMaskIntoConstraints = false

}

@IBAction func openPickerButtonPressed(_ sender: UIButton) {
    guard pickerView.superview == nil else {
        return
    }
    self.view.addSubview(pickerView)
    let viewsDictionary: [String: UIView] = ["pickerView": pickerView]
    view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[pickerView]-0-|", options: [], metrics: nil, views: viewsDictionary))
    view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[pickerView(0)]", options: [], metrics: nil, views: viewsDictionary)) // HEIGHT
    view.addConstraint(NSLayoutConstraint(item: pickerView, attribute: .centerY, relatedBy: NSLayoutConstraint.Relation(rawValue: 0)!, toItem: view, attribute: .centerY, multiplier: 1, constant: 0))
}

Picker View

How can I get the pickerView UIView to open when the openPickerButtonPressed button is pressed?

0

There are 0 best solutions below