diff --git a/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomViewController.swift b/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomViewController.swift index e82d76a..fba3edd 100644 --- a/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomViewController.swift +++ b/Example/JZCalendarWeekViewExample/Source/CustomViews/CustomViewController.swift @@ -32,26 +32,31 @@ class CustomViewController: UIViewController { private func setupCalendarView() { calendarWeekView.baseDelegate = self - // For example only if viewModel.currentSelectedData != nil { + // For example only setupCalendarViewWithSelectedData() - return + } else { + // Normal setup with different visible time + let time8AM = DateComponents(calendar: Calendar.current, timeZone: Calendar.current.timeZone, year: 2018, month: 9, day: 24, hour: 8, minute: 0, second: 0).date! + calendarWeekView.setupCalendar(numOfDays: 3, + setDate: Date(), + allEvents: viewModel.eventsByDate, + scrollType: .pageScroll, + visibleTime: time8AM) } - - calendarWeekView.setupCalendar(numOfDays: 3, - setDate: Date(), - allEvents: viewModel.eventsByDate, - scrollType: .pageScroll) } /// For example only private func setupCalendarViewWithSelectedData() { guard let selectedData = viewModel.currentSelectedData else { return } + + let time8AM = DateComponents(calendar: Calendar.current, timeZone: Calendar.current.timeZone, year: 2018, month: 9, day: 24, hour: 8, minute: 0, second: 0).date! calendarWeekView.setupCalendar(numOfDays: selectedData.numOfDays, setDate: selectedData.date, allEvents: viewModel.eventsByDate, scrollType: selectedData.scrollType, - firstDayOfWeek: selectedData.firstDayOfWeek) + firstDayOfWeek: selectedData.firstDayOfWeek, + visibleTime: time8AM) calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourGridDivision: selectedData.hourGridDivision)) } diff --git a/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist b/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist index 0426508..7b5fe3e 100644 --- a/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist +++ b/Example/JZCalendarWeekViewExample/Supporting Files/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.5.2 + 0.5.3 CFBundleVersion - 18091701 + 18092401 LSRequiresIPhoneOS UILaunchStoryboardName diff --git a/JZCalendarWeekView.podspec b/JZCalendarWeekView.podspec index 7279a11..a7970a1 100644 --- a/JZCalendarWeekView.podspec +++ b/JZCalendarWeekView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "JZCalendarWeekView" - s.version = "0.5.2" + s.version = "0.5.3" s.summary = "Calendar Week & Day View in iOS Swift" s.homepage = "https://github.com/zjfjack/JZCalendarWeekView" s.license = { :type => "MIT", :file => "LICENSE" } diff --git a/JZCalendarWeekView/Info.plist b/JZCalendarWeekView/Info.plist index f5b1a62..a98f4be 100644 --- a/JZCalendarWeekView/Info.plist +++ b/JZCalendarWeekView/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.5.2 + 0.5.3 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/JZCalendarWeekView/JZBaseWeekView.swift b/JZCalendarWeekView/JZBaseWeekView.swift index aff4179..ef2bff8 100644 --- a/JZCalendarWeekView/JZBaseWeekView.swift +++ b/JZCalendarWeekView/JZBaseWeekView.swift @@ -116,19 +116,21 @@ open class JZBaseWeekView: UIView { Basic Setup method for JZCalendarWeekView,it **must** be called. - Parameters: - - numOfDays: number of days in a page - - setDate: the initial set date, the first date in current page except WeekView (numOfDays = 7) + - numOfDays: Number of days in a page + - setDate: The initial set date, the first date in current page except WeekView (numOfDays = 7) - allEvents: The dictionary of all the events for present. JZWeekViewHelper.getIntraEventsByDate can help transform the data - firstDayOfWeek: First day of a week, **only works when numOfDays is 7**. Default value is Sunday - scrollType: The horizontal scroll type for this view. Default value is pageScroll - currentTimelineType: The current time line type for this view. Default value is section + - visibleTime: WeekView will be scroll to this time, when it appears the **first time**. This visibleTime only determines **y** offset. Defaut value is current time. */ open func setupCalendar(numOfDays: Int, setDate: Date, allEvents: [Date:[JZBaseEvent]], scrollType: JZScrollType = .pageScroll, firstDayOfWeek :DayOfWeek? = nil, - currentTimelineType: JZCurrentTimelineType = .section) { + currentTimelineType: JZCurrentTimelineType = .section, + visibleTime: Date = Date()) { self.numOfDays = numOfDays if numOfDays == 7 { @@ -146,7 +148,7 @@ open class JZBaseWeekView: UIView { if self.isFirstAppear { self.isFirstAppear = false - self.flowLayout.scrollCollectionViewToCurrentTime() + self.flowLayout.scrollCollectionViewTo(time: visibleTime) } } } diff --git a/JZCalendarWeekView/JZWeekViewFlowLayout.swift b/JZCalendarWeekView/JZWeekViewFlowLayout.swift index 5166a9c..397347e 100644 --- a/JZCalendarWeekView/JZWeekViewFlowLayout.swift +++ b/JZCalendarWeekView/JZWeekViewFlowLayout.swift @@ -669,8 +669,10 @@ open class JZWeekViewFlowLayout: UICollectionViewFlowLayout { } } - open func scrollCollectionViewToCurrentTime() { - let y = max(0, min(CGFloat(Calendar.current.component(.hour, from: Date())) * hourHeight - collectionView!.frame.height / 2 + columnHeaderHeight, + /// Vertically scroll the collectionView to specific time in a day, only **hour** will be calulated for the offset. + /// If the hour you set is too large, it will only reach the bottom 24:00 as the maximum value. + open func scrollCollectionViewTo(time: Date) { + let y = max(0, min(CGFloat(Calendar.current.component(.hour, from: time)) * hourHeight, collectionView!.contentSize.height - collectionView!.frame.height)) self.collectionView!.setContentOffsetWithoutDelegate(CGPoint(x: self.collectionView!.contentOffset.x, y: y), animated: false)