Reputation: 885
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
Reputation: 645
UICollectionView is a sub class of UIScrollView. Anyone can detect the delegate methods of scroll view by keeping in mind some points.
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
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