I have an FSCalendar component and a UITableView within a vertical UIStackView. It was setup using Interface Builder. The stack view is set to fill equally, and I have constraints that pin the height and width of the FSCalendar and UITableView to be equal. The calendar renders fine on initial load. However, once the device rotates, the layout of the calendar is all messed up. The month header at the top becomes off-center and swiping from month-to-month reveals that the day layout is also completely messed up.
I've tried implementing func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) within my FSCalendarDelegate (as is mentioned on the project home page), but this method is never called.
I'd assume this is a bug within FSCalendar, but I don't know of a workaround to address this behavior. Thoughts?
UPDATE:
I found a mention to overriding func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) as a potential workaround to this issue. My implementation looks looks like this:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: { (UIViewControllerTransitionCoordinatorContext) in
self.calendar?.reloadData()
}, completion: nil)
}
At this point, the date cells themselves are rendered properly. However, the month header at the top of the calendar remains incorrect. I don't know if this helps diagnose the issue or not, but it does change the behavior.
I had the same issue and added calendar programmatically in view. I resolved it with calendar.adjustMonthPosition()
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil) { (_) in
self.calendar.reloadData()
self.calendar.adjustMonthPosition()
}
}
I have the same issue, the viewWillTransition that was suggested fixed the days but the header is off center and the year shows 2035.
@keithmichelson I have exactly the same issue, did you find a fix? I am manually setting the frame of the calendar.
I had the same issue. There seems a bug in FSCalendarHeaderView.m's method
I my case, this enhancement fixed this problem. But its ... creepy!
override func viewWillTransition(to size: CGSize,
with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil,
completion: { transitionCoordinatorContext in
self.calendarView.reloadData()
/* HACK: force reload of calendarHeaderView to show correct
month and year after a rotation. Terrible! */
self.calendarView.scrollDirection = .vertical
self.calendarView.scrollDirection = .horizontal
})
}
@ricsantos Does this work for you?
An Update:
This bug could be related to https://github.com/WenchaoD/FSCalendar/issues/782
In other words: with _UIRequiresFullScreen = true_ in info.plist I don't need to override viewWillTransition().
Most helpful comment
I had the same issue. There seems a bug in FSCalendarHeaderView.m's method
I my case, this enhancement fixed this problem. But its ... creepy!