From 01f9a1ad85acd438dcd17e6c2ee37be04b221eee Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Wed, 7 Feb 2018 13:51:11 -0500 Subject: [PATCH] Fix overscroll on TimelineContainer --- Source/Timeline/TimelineContainer.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Timeline/TimelineContainer.swift b/Source/Timeline/TimelineContainer.swift index 2bba951a..144ac435 100644 --- a/Source/Timeline/TimelineContainer.swift +++ b/Source/Timeline/TimelineContainer.swift @@ -23,7 +23,7 @@ public class TimelineContainer: UIScrollView, ReusableView { public func scrollToFirstEvent() { if let yToScroll = timeline.firstEventYPosition { - setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll - 15), animated: true) + setTimelineOffset(CGPoint(x: contentOffset.x, y: yToScroll - 15), animated: true) } } @@ -31,6 +31,13 @@ public class TimelineContainer: UIScrollView, ReusableView { let percentToScroll = CGFloat(hour24 / 24) let yToScroll = contentSize.height * percentToScroll let padding: CGFloat = 8 - setContentOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: true) + setTimelineOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: true) + } + + private func setTimelineOffset(_ offset: CGPoint, animated: Bool) { + let yToScroll = offset.y + let bottomOfScrollView = contentSize.height - bounds.size.height + let newContentY = (yToScroll < bottomOfScrollView) ? yToScroll : bottomOfScrollView + setContentOffset(CGPoint(x: offset.x, y: newContentY), animated: animated) } }