Progress of UIPageViewController

后端 未结 7 1071
礼貌的吻别
礼貌的吻别 2020-12-30 05:51

I would like to receive updates from the uipageviewcontroller during the page scrolling process. I want to know the transitionProgress in %. (This value should update when t

相关标签:
7条回答
  • 2020-12-30 06:22

    At last I found out a solution, even if it is probably not the best way to do it:

    I first add an observer on the scrollview like this:

    // Get Notified at update of scrollview progress
    NSArray *views = self.pageViewController.view.subviews;
    UIScrollView* sW = [views objectAtIndex:0];
    [sW addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];
    

    And when the observer is called:

    NSArray *views = self.pageViewController.view.subviews;
    UIScrollView* sW = [views objectAtIndex:0];
    CGPoint point = sW.contentOffset;
    
    float percentComplete;
    //iPhone 5
    if([ [ UIScreen mainScreen ] bounds ].size.height == 568){
        percentComplete = fabs(point.x - 568)/568;
    
    } else{
    //iphone 4
        percentComplete = fabs(point.x - 480)/480;
    }
    NSLog(@"percentComplete: %f", percentComplete);
    

    I'm very happy that I found this :-)

    0 讨论(0)
提交回复
热议问题