Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a UI scroll view scroll with a UIPageViewController

I am creating an app where I am trying to have a pagescrollviewcontroller swipe through screens and have the top "nav" bar titles scroll real time with the titles i have the title bar view as a custom view and I am able to access the scroll delegate methods for both the custom scroll view and the pageview controller. However. I don't see how to access the real time scroll pos? I know it is possible because twitter does it (really can't shouldn't be in anyone's vocabulary) but I am not sure how to achieve this.

a pictureenter image description here

the home title swipes at the same scroll pos as the pagecontrollers.

current code:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    if(scrollView.tag == 100) {
      CGPoint point = CGPointMake(mainScrollView.contentOffset.x * 1,0);
      [titleSwipe setContentOffset:point animated:YES];
    }
    else {
        mainScrollView.contentOffset = CGPointMake(0,1);
        [mainScrollView setContentOffset:titleSwipe.contentOffset animated:YES];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:     (BOOL)decelerate {

    CGPoint point = CGPointMake(mainScrollView.contentOffset.x * 2,0);

    [titleSwipe setContentOffset:point animated:YES];

}
like image 714
Dnaso Avatar asked Feb 10 '26 03:02

Dnaso


1 Answers

You'll find the real time position in scrollViewDidScroll:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    // X scroll
    //
    CGFloat percentage = scrollView.contentOffset.x / scrollView.contentSize.width;
    NSLog(@"Scrolled percentage: %f", percentage);
}

Hope that helps!

like image 133
jbouaziz Avatar answered Feb 15 '26 18:02

jbouaziz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!