User1075
User1075

Reputation: 885

scrollViewWillBeginDragging: Not getting called in UICollectionview

I have an UIView in which an UICollectionview is there. For knowing the scroll distance of UICollectionview I used scrollViewWillBeginDragging: , but it is not getting called. Sample Code is

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    CGPoint translation = [scrollView.panGestureRecognizer translationInView:scrollView.superview];

    if(translation.y > 0)
    {
        //dragging down
        _reusableview.backgroundColor = [UIColor blackColor];
    } 
    else
    {
        // dragging up
        _reusableview.backgroundColor = [UIColor clearColor];
    }
}

Can anyone help me please?

Upvotes: 3

Views: 3121

Answers (2)

Davinder Singh
Davinder Singh

Reputation: 645

UICollectionView is a sub class of UIScrollView. Anyone can detect the delegate methods of scroll view by keeping in mind some points.

  1. Set the class as delegate of scroll view You can do this in .h file and .m file

In .h file

@interface DemoViewController : UIViewController<UIScrollViewDelegate>
{

}

In .m file

@interface SplashViewController ()<UIScrollViewDelegate>
{

}

2. Make the datasource and delegate of collection view that class. Example:

collectionView.delegate = self;
collectionView.dataSource = self;

Try out above steps. Hope it will work for you.

Upvotes: 1

Sujith Chandran
Sujith Chandran

Reputation: 2731

Hope you have added the UIscrollViewDelegate and set the UIcollectionView delegate to the class. Then scrollViewWillBeginDragging() function will be called when collectionView is scrolled.

Inside the function you can confirm if the scrollView isKindOfClass UICollectionView.

Upvotes: 1

Related Questions