Muszę wykonać określone działanie, gdy użytkownik przeciągnie widok pikowania. Zbudowałem go w taki sposób, że każda komórka przechwytuje cały ekran.Wykryj przesuwanie w UICollectionView
Próbowałem te sposoby:
A. scrollViewDidEndDecelerating
# pragma UIScrollView
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(@"detecting scroll");
for (UICollectionViewCell *cell in [_servingTimesCollectionView visibleCells]) {
NSIndexPath *indexPath = [_servingTimesCollectionView indexPathForCell:cell];
CGPoint scrollVelocity = [scrollView.panGestureRecognizer velocityInView:_servingTimesCollectionView];
if (scrollVelocity.x > 0.0f)
NSLog(@"going right");
else if (scrollVelocity.x < 0.0f)
NSLog(@"going left");
}
}
Ale scrollVelocity
zwraca NULL. Metoda jest wywoływana.
B. UISwipeGestureRecognizer
W ViewDidLoad
moich UIViewController
które delegatów UICollectionViewDataSource
i UIGestureRecognizerDelegate
I dodaje:
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
swipeRight.numberOfTouchesRequired = 1;
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)];
swipeRight.numberOfTouchesRequired = 1;
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[_servingTimesCollectionView addGestureRecognizer:swipeRight];
[_servingTimesCollectionView addGestureRecognizer:swipeLeft];
i co nastepuje w UIViewController:
#pragma mark - UISwipeGestureRecognizer Action
-(void)didSwipeRight: (UISwipeGestureRecognizer*) recognizer {
NSLog(@"Swiped Right");
}
-(void)didSwipeLeft: (UISwipeGestureRecognizer*) recognizer {
NSLog(@"Swiped Left");
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
NSLog(@"Asking permission");
return YES;
}
ale żaden są nazywane.
Co jest nie tak? Zajmuję dla ios7