gpt4 book ai didi

ios - Swift:未使用 viewWillTransition 中调用函数的结果

转载 作者:行者123 更新时间:2023-11-28 15:47:24 26 4
gpt4 key购买 nike

我正在使用具有两种 View 类型的日历 cocoapod(CVCalendar:https://github.com/CVCalendar/CVCalendar);周 View 和月 View 。 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 上,我会尝试显示 weekView,如果它显示在其他任何东西上,我会尝试显示 monthView。然后我调用 viewWillTransition 中的函数:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

self.presentationMode()

}

但是,当使用上面的代码时,我收到警告“Result of call to 'presentationMode' is unused and the view does not change to weekView in IPhone Lanscape.

最佳答案

请更新函数

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()
}

关于ios - Swift:未使用 viewWillTransition 中调用函数的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42813259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com