patchthecode/JTAppleCalendar

Question on displaying vertical scrolling calendar with headers.

Open

#850 opened on Aug 6, 2018

View on GitHub
 (12 comments) (0 reactions) (0 assignees)Swift (819 forks)batch import
help wanted

Repository metrics

Stars
 (7,660 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Hi,

Thanks for making this really neat calendar framework, very helpful.

I am using the latest version 7.1.5 .This is more of a question of how to than an issue. Not sure where to post such queries, hence opening it as an issue.

I have a vertical scrolling calendar ( number of rows is 6) with headers enabled. The headers have a fixed height of 44.0 each. The scrolling mode is .stopAtEachSection . As per the current implementation, when headers are enabled , the calendar shows the header also when displaying each section. However, I would like to display only the dates for the month and the section headers will show only while scrolling. ( Similar to the month view on the iPhone calendar app).

In UIScrollViewDelegates.swift , I tried to adjust the offsets, based on the header height of 44 as in the snippet below. ( Also on startup of the calendar, I call scrollToHeaderForDate: with an extraAddedOffset of 44) . Although this achieves what I am trying to do, there is one issue. When the user doesn't do a full scroll ( lifts the finger after a short distance immediately, then it should scroll back to the same section that was being displayed and should not scroll to the previous or next section). However, with my changes for the offset, even after a slight change, it scrolls to to the next or previous sections ( based on the direction).

Is there any other place to adjust the offset to prevent this from happening or is there a more elegant way to achieve what I am trying to do? Have attached a snap shot of the native iOS calendar look that I am trying to achieve. Thanks very much for your help.

    case .stopAtEachSection:
        var calculatedOffSet: CGFloat = 44.0//0
        if scrollDirection == .horizontal ||
            (scrollDirection == .vertical && !calendarViewLayout.thereAreHeaders && cachedConfiguration.generateOutDates == .tillEndOfGrid) {
            // Horizontal has a fixed width.
            // Vertical with no header has fixed height
            let interval = calendarLayout.sizeOfContentForSection(theCurrentSection)
            calculatedOffSet = calculatedCurrentFixedContentOffsetFrom(interval)
        } else {
            // Vertical with headers have variable heights.
            // It needs to be calculated
            let currentScrollOffset = scrollView.contentOffset.y
            let currentScrollSection = calendarLayout.sectionFromOffset(currentScrollOffset)
            var sectionSize: CGFloat = 0
            if isScrollingForward() {
                sectionSize = calendarLayout.sectionSize[currentScrollSection]
                calculatedOffSet = sectionSize  + 44
            } else {
                if currentScrollSection - 1  >= 0 {
                    calculatedOffSet = calendarLayout.sectionSize[currentScrollSection - 1] + 44
                }
            }
        }
        setTargetContentOffset(calculatedOffSet)

Contributor guide