2017-03-15 1 views
0

두 가지보기 유형이있는 달력 cocoapod (CVCalendar : https://github.com/CVCalendar/CVCalendar)를 사용하고 있습니다. weekView 및 monthView. 다음 함수는 포드에 필요하며 나는 클래스 확장 내에 있습니다스위프트 : viewWillTransition 내 함수 호출 결과가 사용되지 않습니다.

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

가에 표시되어있는 경우에, 나는 달력은 풍경에 아이폰에 표시되어있는 경우 weekView을 제시하려고, 또는 monthView하고 다른 것. 그때 viewWillTransition에서 함수를 호출 오전 : 나는 presentationMode 경고 '에 대한 호출의 결과'를 얻을 수 위의 코드를 사용하지만

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

     self.presentationMode() 

    } 

'는 사용되지 않고 뷰는 아이폰 Lanscape입니다에 weekView 변경되지 않습니다.

+0

먼저 기능을 업데이트하시기 바랍니다. 경고는'presentationMode()'의 반환 값이 무엇이든 할당되지 않았기 때문에'CVCalendar'의'CalendarMode'를 설정해야한다는 것입니다. –

답변

1

첫 번째 줄`당신이 함수에서 반환되기 때문에 return.weekView`가 실행되지 않습니다 후`presentationMode()`모든 일에

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

응답 해 주셔서 감사합니다. 덕분에 테스트했을 때 weekView로 캘린더를 업데이트하고 있습니다! 그러나보기 내의 캘린더 날짜 버튼/아이콘은 같은 위치에 있습니다. viewWillTransition 함수 내에서 view.layoutIfNeeded를 추가하려고 시도했지만이 영향도 미치지 않습니다. 어떤 제안? –

+0

아, 문제 없습니다. 당신은 어쨌든 내 초기 문제를 해결해 주셔서 감사합니다! –

관련 문제