Add a function to scroll to top when the header view is sticked.#86
Open
wanderingfairy wants to merge 2 commits intoJiar:masterfrom
Open
Add a function to scroll to top when the header view is sticked.#86wanderingfairy wants to merge 2 commits intoJiar:masterfrom
wanderingfairy wants to merge 2 commits intoJiar:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #86 +/- ##
==========================================
- Coverage 73.58% 72.64% -0.95%
==========================================
Files 11 11
Lines 106 106
==========================================
- Hits 78 77 -1
- Misses 28 29 +1
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.contentOffsetare ignored when theheaderViewis in the sticked state is related to thescrollView.observe()method.As soon as
scrollView.contentOffsetis changed, theparentScrollViewDidScroll(_:)is called immediately, andparentContentOffsetYis compared withheaderStickyHeight.And because
parentScrollView.contentOffset.yis 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 disablesparentKeyValueObservationfor 2 seconds. If the deactivation time is too short,contentOffset.yis intercepted by theobserve()method before moving to the top, so I set it to 2 seconds.contentOffset.yis reset to zero for 2 seconds whenparentKeyValueObservationis disabled.Like
resetCurrentChildViewControllerContentOffsetYorresetOtherCachedChildViewControllerContentOffsetY, theparentViewControllerneeds a method to scroll to the top.If you call
self.resetCurrentParentViewControllerContentOffsetY(scrollView)in SegementSlideViewController, thescrollViewis scrolled to the top of thescrollVieweven ifheaderViewis sticked.Thank you.