Question

In order to scroll up and down i need to call two methods for that I have used the below method .I am using scrollview delegate method for UICollection as it is the subview for UIScrollView.Here is the code that I have written but the scroll is not easily moving and the result is also not accurate for some times can any one suggest.?

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    CGPoint mScrollPosition = [scrollView.panGestureRecognizer velocityInView:mCollectionView];


    if (mScrollPosition.y > 0.0f){
        NSLog(@"going down");
       //Action One
        mYearHeaderTitle--;
        [self.mCollectionView reloadData];

    }
    else if (mScrollPosition.y < 0.0f){
        NSLog(@"going up");
      //Action two
        mYearHeaderTitle++;
        [self.mCollectionView reloadData];
    }
}
Was it helpful?

Solution

Use :

  1. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  2. - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

Instead :

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

OTHER TIPS

Use the following methods:

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView

 - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

Connect delegate to scroll view by right click on scroll view and connect to delegate method to file's owner (or)

scrollview.delegate = self;

You can try setting self.scrollView.delegate to the object that should act as a delegate to the scrollView.

Set your view controller up as a <UIScrollViewDelegate>

**Use This : **

  //MARK: - UIScrollview Delegate -
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    if scrollView.contentOffset.y > 0
    {
        if (tableView.contentSize.height - (tableView.contentOffset.y + scrollView.bounds.size.height)) == 0
        {
            self.count += 1
            let strCount = String(self.count)
            let params:[String:String] = ["search":SAFESTRING(str: self.strSearchVal!),"page":strCount,"length":"25"]
            let url = API_USER.BASE_URL + API_USER.SEARCH_LISTING
            self.callGetEventlist(url: url, params: params)
        }
        else
        {

        }
    }
}

//MARK: - Use For Pegination -
func scrollViewDidScroll(_ scrollView: UIScrollView) {

    if (NetworkReachabilityManager()?.isReachable)! {
        if (((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height ) && !isLoadingList){
            self.isLoadingList = true
            currentPage += 1
            self.getList(page: currentPage)
        }
    }
}

In my case I had to make my view both a delegate for UITextViewDelegate and UIScrollViewDelegate. It wouldn't trigger the method until I added both. Probably because I'm in an EAGLView and not a viewcontroller.

@interface EAGLView : UIView <UITextFieldDelegate, SDWebImageManagerDelegate, UITextViewDelegate, UIScrollViewDelegate>

I also did the:

alertMessage.delegate = self;

As alertMessage is my TextView that I'm using as a Terms of Service scroller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top