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

How to scroll MXScrollView to top programmatically #13

Open
andiradulescu opened this issue Mar 8, 2016 · 6 comments
Open

How to scroll MXScrollView to top programmatically #13

andiradulescu opened this issue Mar 8, 2016 · 6 comments
Labels

Comments

@andiradulescu
Copy link

I tried with setContentOffset but it doesn't work.

[self.scrollView setContentOffset:CGPointMake(0, -self.scrollView.contentInset.top)];

Thanks!

@andiradulescu
Copy link
Author

As a workaround I'm calling scrollView:setContentOffset: since it disables KVO in MXScrollView while you change it.

[self.scrollView scrollView:scrollView setContentOffset:CGPointMake(0, -self.scrollView.contentInset.top)];

Of course I had to expose it in a category.

@interface MXScrollView ()
- (void) scrollView:(UIScrollView*)scrollView setContentOffset:(CGPoint)offset;
@end

@maxep
Copy link
Owner

maxep commented Mar 9, 2016

Hi @andiradulescu
Yes the contentoffset is locked by KVO, I will try to find a fix.

@maxep maxep added the bug label Mar 9, 2016
@andiradulescu
Copy link
Author

Hi @maxep! Thanks!
I would've tried to find a fix myself (instead of the workaround), but I'm not sure what is the correct approach.

@nweintraut
Copy link

Max,
Hi and Thanks.
Another need / vote to enable programmatic scrolling.
Neil

@rahulvyas
Copy link

[self.scrollView scrollView:scrollView setContentOffset:CGPointMake(0, -self.scrollView.contentInset.top)];

Where did you put this code ?

@ngochiencse
Copy link

@andiradulescu @rahulvyas @nweintraut @maxep @loicgardiol
Hi, I have forked this library into swift version called HPParallaxHeader: https://github.com/ngochiencse/HPParallaxHeader
If you need to perform tap on status bar to scroll to top, HPParallaxHeader automatically handle for you.
If you need to scroll to top programatically, I have created this method for you:

/**
     Scroll to top manually which show parallax header totally
*/
open func hpScrollsToTop(animated: Bool)

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

No branches or pull requests

5 participants