UIPageViewControllerDatasource calling both swipe left and swipe right methods

坚强是说给别人听的谎言 提交于 2019-12-05 12:12:28

Looks like 'UIPageviewcontroller' is not really using the 'UIScrollViewDelegate'. So subclassing the 'UIPageViewController' and using the 'UIScrollViewDelegate' seems to do the trick to find out wether its forward swipe or backward swipe.

//Get Scroll View from PageViewController the scrollView

 - (void)viewDidLoad
     {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        for (UIView* v in [self.view subviews]){
            if ([v isKindOfClass:[UIScrollView class]]){
                _scrollView = (UIScrollView*)v;
            }
        }

        if (_scrollView){
            _scrollView.delegate = self;
        }
    }

//Record content offset when scroll view begins dragging

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    _startContentOffset = _scrollView.contentOffset;
    _transitionState = SurveyPageviewCtlrTransitionInitiated;
    [_transitionStateDelegate transitionInitiated:self];
}

// Direction based on displacement

 -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (_scrollView.contentOffset.x > _startContentOffset.x){
       [self.delegate forwardDrag];
     }
     else{
       [self.delegate reverseDrag];
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!