这是 CalendarKit 库中的一个错误,已在以下提交中修复:Fix Layout Issue when using UISplitViewController
问题出在没有考虑safeArea
指南的布局代码中:
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))
切换到 AutoLayout 后,问题就消失了:
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