Add a function to scroll to top when the header view is sticked. #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To fix the issue in #67, a function was added.
The reason why changes to
scrollView.contentOffset
are ignored when theheaderView
is in the sticked state is related to thescrollView.observe()
method.As soon as
scrollView.contentOffset
is changed, theparentScrollViewDidScroll(_:)
is called immediately, andparentContentOffsetY
is compared withheaderStickyHeight
.And because
parentScrollView.contentOffset.y
is reset based on the comparison result in the switch statement, the 'scroll to top' operation desired by the user is not executed.In order to bypass
parentScrollViewDidScroll(_:)
with minimal impact on other parts, I added a function that disablesparentKeyValueObservation
for 2 seconds. If the deactivation time is too short,contentOffset.y
is intercepted by theobserve()
method before moving to the top, so I set it to 2 seconds.contentOffset.y
is reset to zero for 2 seconds whenparentKeyValueObservation
is disabled.Like
resetCurrentChildViewControllerContentOffsetY
orresetOtherCachedChildViewControllerContentOffsetY
, theparentViewController
needs a method to scroll to the top.If you call
self.resetCurrentParentViewControllerContentOffsetY(scrollView)
in SegementSlideViewController, thescrollView
is scrolled to the top of thescrollView
even ifheaderView
is sticked.Thank you.