Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird _adjustContentOffsetIfNecessary changed my contentOffset #31

Open
liuxuan30 opened this issue Apr 28, 2015 · 1 comment
Open

weird _adjustContentOffsetIfNecessary changed my contentOffset #31

liuxuan30 opened this issue Apr 28, 2015 · 1 comment

Comments

@liuxuan30
Copy link

I have two tabs, each contains one UICollectionView. I embed SVPullToRefresh in each UICollectionView as well. I set up the snapping by 0.5 threshold for BLK height bar.

tab 1 has 6 cells and tab 2 has 20 cells, so tab 2 could snap to progress 1, while tab 1 cannot.
My behaviour is copied from Facebook style behaviour:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if(!self.isCurrentlySnapping)
    {
        CGFloat deltaYOffset = scrollView.contentOffset.y - self.previousYOffset;
        CGFloat deltaProgress = deltaYOffset / (self.flexibleHeightBar.maximumBarHeight-self.flexibleHeightBar.minimumBarHeight);

        self.flexibleHeightBar.progress = self.previousProgress + deltaProgress;
        NSLog(@"contentOffset Y %f, previousYOffset:%f, progress %f",scrollView.contentOffset.y,self.previousYOffset, self.previousProgress + deltaProgress);

        [self.flexibleHeightBar setNeedsLayout];
    }
}

everytime when switching tab, I will update the UICollectionView like this:

targetCollection.delegate = (id<UICollectionViewDelegate>)self.delegateSplitter;
targetCollection.contentOffset = CGPointMake(targetCollection.contentOffset.x, -CGRectGetHeight(self.BLKBar.frame));

the second line is to keep the BLKBar height consistent while switching between tabs. e.g. When the BLK height bar is at minimum height, I should keep it, so I need to update the offset when switching to target tab.

Steps:
First, I switch from tab 1 to tab 2; BLKBar is at progress 0;
when I am on tab 2, I scroll the UICollectionView, snap BLKBar to progress 1;
Then I switch to tab 1 by paning horizontally, ideally the BLK Bar should keep the snapping at progress 1, aka minimum height, however, I found it is at progress 0!

In order to debug, I subclass a HackUICollectionView to see what is happenning.

I setup my BLKBar minimum height is 64, max height is 108.

so while debugging, after
targetCollection.contentOffset = CGPointMake(targetCollection.contentOffset.x, -CGRectGetHeight(self.BLKBar.frame));
is set to (0,-64),

there is one API called _adjustContentOffsetIfNecessary changed my contentOffset to -108:

...
    frame #8: 0x000000010a008bda UIKit`-[UIScrollView setContentOffset:] + 645
    frame #9: 0x000000010969e3ca MCompass`-[HackUICollectionView setContentOffset:](self=0x00007f8279854e00, _cmd=0x000000010a765895, contentOffset=(x = 0, y = -108)) + 74 at HackUICollectionView.m:14
    frame #10: 0x0000000109b5bbf6 Foundation`_NSSetPointValueAndNotify + 139
    frame #11: 0x000000010a01d535 UIKit`-[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 1445
    frame #12: 0x000000010a01a727 UIKit`-[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 417
...

If I override _adjustContentOffsetIfNecessary in sub class, it will not change it to -108 obviously, but I CANNOT fix my problem by this way because it is a internal API, I cannot simply pass through it.

Any idea why this happened? How can I keep the progress while switching UICollectionViews?

@bryankeller
Copy link
Owner

Thanks for the detailed explanation. I'll look into this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants