0
votes

I would like to add a container view to my UISplitViewController in such a way that its always in the center of the screen. My problem is that I have a master and detail so the container view can't really belong to either one. Right? I guess the main issue is how to display it when in allVisible mode (when both master and detail are shown).

Is this possible?

1

1 Answers

0
votes

After some digging, the answer is YES and was somewhat embedded in the question: add the container view to the UISplitViewController which in and of itself is a containerView.

containerView = UIView()
containerView.backgroundColor = UIColor.green
containerView.alpha = 0.5
containerView.translatesAutoresizingMaskIntoConstraints = false

let spvcView = splitViewController!.view!
spvcView.addSubview(containerView)
NSLayoutConstraint.activate([
  containerView.leadingAnchor.constraint(equalTo: spvcView.leadingAnchor, constant: 50),
  containerView.trailingAnchor.constraint(equalTo: spvcView.trailingAnchor, constant: -50),
  containerView.topAnchor.constraint(equalTo: spvcView.topAnchor, constant: 50),
  containerView.bottomAnchor.constraint(equalTo: spvcView.bottomAnchor, constant: -50),
  ])

That's it!