我正在使用日历cocoapod(CVCalendar:https://github.com/CVCalendar/CVCalendar),它有两种视图类型; weekView和monthView。 pod中需要以下功能,我在类扩展中使用它:
func presentationMode() -> CalendarMode {
let isPhone: Bool = UIDevice.current.userInterfaceIdiom == .phone
let isLandscape: Bool = UIDevice.current.orientation.isLandscape
if isPhone == true && isLandscape == true {
return.weekView
} else {
return .monthView
}
}
如果日历显示在横向上的iPhone上,或者如果它显示在其他任何内容上的monthView,我试图呈现weekView。然后我在viewWillTransition中调用函数:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
self.presentationMode()
}
但是当使用上面的代码时,我收到警告'调用'presentationMode'的结果未使用,视图不会更改为IPhone Lanscape中的weekView。
答案 0 :(得分:1)
请更新功能
func presentationMode() -> CalendarMode {
let isPhone: Bool = UIDevice.current.userInterfaceIdiom == .phone
let isLandscape: Bool = UIDevice.current.orientation.isLandscape
if isPhone == true && isLandscape == true {
return.weekView
} else {
return .monthView
}
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
self.calendarView.calendarMode = self.presentationMode()
self.calendarView.commitCalendarViewUpdate()
}