7

में स्वाइपिंग का पता लगाएं जब उपयोगकर्ता uicollectionview को स्वाइप करता है तो मुझे एक विशिष्ट क्रिया करने की आवश्यकता होती है। मैंने इसे इस तरह से बनाया है कि प्रत्येक सेल पूर्ण स्क्रीन को कैप्चर करता है।UICollectionView

ए 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"); 
    } 
} 

लेकिन scrollVelocity रिटर्न अशक्त:

मैं उन तरीकों की कोशिश की। विधि कहा जा रहा है।

बी UISwipeGestureRecognizer

UICollectionViewDataSource करने के लिए

मेरी UIViewController जो प्रतिनिधियों की ViewDidLoad में और UIGestureRecognizerDelegate मैं कहा:

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]; 

और 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; 
} 

लेकिन कोई भी कहा जाता है।

क्या गलत है? मैं iOS7

उत्तर

8

के लिए विकसित कर रहा हूँ तुम इशारों के प्रतिनिधि की स्थापना नहीं कर रहे हैं:

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)]; 
    swipeRight.delegate = self; 
    swipeRight.numberOfTouchesRequired = 1; 
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; 

    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)]; 
    swipeLeft.delegate = self; 
    swipeLeft.numberOfTouchesRequired = 1; 
    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];