我正在尝试使我的CVCalendar视图与屏幕旋转兼容,如果设备是iphone并且在横向上,视图将切换到weekView,如果还有其他任何内容将在monthView中。这是我的代码:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
let isPhone: Bool = UIDevice.current.userInterfaceIdiom == .phone
let isLandscape: Bool = UIDevice.current.orientation.isLandscape
coordinator.animate(alongsideTransition: nil, completion: {
_ in
if isLandscape && isPhone {
self.calendarView.changeMode(.weekView)
} else {
self.calendarView.changeMode(.monthView)
}
}
}
此代码适用于过渡到.weekView。但是当转换回iphone 6,7上的.monthView并加上'日历视图日期超出了calendarView。