开发者

UIScrollView direction from scrollViewWillBeginDecelerating

开发者 https://www.devze.com 2023-03-03 22:01 出处:网络
Is it possible to retrieve the direction that a UIScrollView is scrolling to, in the method;开发者_如何学Python

Is it possible to retrieve the direction that a UIScrollView is scrolling to, in the method;

开发者_如何学Python

-(void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

If so, how can this be achieved?


you could try something like this:

- (void)scrollViewDidScroll:(UIScrollView *)sender 
{
  xCoord = scrollview.contentOffset.x;
}

-(void) scrollViewWillBeginDecelerating:(UIScrollView *)sender 
{

   if (xCoord > scrollView.contentOffset.x) {
     //RIGHT
   } else if (xCoord < scrollView.contentOffset.x) {
     //LEFT
   }

}

store the x coord of the scrollViews contentOffset when it begins scrolling, then compare it in scrollViewWillBeginDecelerating


In the case of paging try this

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

    _xCoord = scrollView.contentOffset.x;
}

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

    if (_xCoord > scrollView.contentOffset.x) {
      //right
    } else if (_xCoord < scrollView.contentOffset.x) {
        //LEFT

    }

}


Not directly answering the question, but might be useful for some – to retrieve the direction that a UIScrollView will decelerate:

func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
  let point = scrollView.panGestureRecognizer.translation(in: scrollView)
  if point.x < 0 {
    // Will decelerate to the right
  }else if point.x > 0{
    // Will decelerate to the left
  }
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消