1

In my app, i am using a UISplitViewController like this:

let splitViewController = UISplitViewController()
splitViewController.preferredDisplayMode = .oneBesideSecondary
splitViewController.viewControllers = [
    UINavigationController(rootViewController: CalendarViewController()),
    DetailViewController()
]

Result:

enter image description here

But when i set the style to doubleColumn like this:

let splitViewController = UISplitViewController(style: .doubleColumn)

The Result looks like this:

enter image description here

i don't understand why now CalendarViewController is wider than master view. I would like to use the sidebar so that the user can show and hide the Calendar.

How can I fix this display error so that CalendarViewController has the same width as master view?

Niklas
  • 1,638
  • 4
  • 19
  • 48

1 Answers1

1

It was a bug in the CalendarKit library and it has been fixed in the following commit: Fix Layout Issue when using UISplitViewController

The problem was in the layout code that didn't account for safeArea guides:

      dayHeaderView.frame = CGRect(origin: CGPoint(x: 0, y: layoutMargins.top),
                                   size: CGSize(width: bounds.width, height: headerHeight))
      let timelinePagerHeight = bounds.height - dayHeaderView.frame.maxY
      timelinePagerView.frame = CGRect(origin: CGPoint(x: 0, y: dayHeaderView.frame.maxY),
                                       size: CGSize(width: bounds.width, height: timelinePagerHeight))

After switching to AutoLayout, the issue has gone away:

      dayHeaderView.translatesAutoresizingMaskIntoConstraints = false
      timelinePagerView.translatesAutoresizingMaskIntoConstraints = false

      dayHeaderView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor).isActive = true
      dayHeaderView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor).isActive = true
      dayHeaderView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor).isActive = true
      let heightConstraint = dayHeaderView.heightAnchor.constraint(equalToConstant: headerHeight)
      heightConstraint.priority = .defaultLow
      heightConstraint.isActive = true

      timelinePagerView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor).isActive = true
      timelinePagerView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor).isActive = true
      timelinePagerView.topAnchor.constraint(equalTo: dayHeaderView.bottomAnchor).isActive = true
      timelinePagerView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115