9

मेरे पास एक संग्रह दृश्य है। मैं स्क्रॉल दिशा का पता लगाना चाहता हूँ। स्क्रॉल करने और स्क्रॉल करने के लिए मेरे पास दो अलग-अलग एनीमेशन शैली हैं। तो मुझे स्क्रॉल दिशा सीखनी चाहिए।आईओएस UICollectionView स्क्रॉल दिशा का पता लगाएं

CGPoint scrollVelocity = [self.collectionView.panGestureRecognizer 
velocityInView:self.collectionView.superview]; 

if (scrollVelocity.y > 0.0f) 
NSLog(@"scroll up"); 

else if(scrollVelocity.y < 0.0f)  
NSLog(@"scroll down"); 

यह सिर्फ उंगली को छूने पर काम करता है। काम नहीं मेरे लिए

उत्तर

26

आज़माएं:

@property (nonatomic) CGFloat lastContentOffset; 

तो ओवरराइड scrollViewDidScroll: विधि:

#pragma mark - UIScrollViewDelegate 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    if (self.lastContentOffset > scrollView.contentOffset.y) 
    { 
     NSLog(@"Scrolling Up"); 
    } 
    else if (self.lastContentOffset < scrollView.contentOffset.y) 
    { 
     NSLog(@"Scrolling Down"); 
    } 

    self.lastContentOffset = scrollView.contentOffset.y; 
} 

में Finding the direction of scrolling in a UIScrollView?

+0

यह वह जगह है में मदद करता है उम्मीद है कि काम करता है धन्यवाद –

2

मैं मिले

इस कहीं आप में शीर्ष लेख जोड़ें यह पता लगाने का एक तरीका खोजने का प्रयास कर रहा था कि उपयोगकर्ता क्या है अधिकतर लंबवत या क्षैतिज स्क्रॉल व्यू खींचने की कोशिश कर रहे हैं। मैं तुम्हें मेरी समाधान देने के लिए, मुझे आशा है कि यह किसी के लिए उपयोगी हो सकता है:

CGPoint _lastContentOffset; 

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 
    _lastContentOffset = scrollView.contentOffset; 
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { 

    if (ABS(_lastContentOffset.x - scrollView.contentOffset.x) < ABS(_lastContentOffset.y - scrollView.contentOffset.y)) { 
     NSLog(@"Scrolled Vertically"); 
    } else { 
     NSLog(@"Scrolled Horizontally"); 
    } 

} 

यह काम मेरे लिए खोजने के लिए और जब खड़ी और विपरीत स्क्रॉल मैं इस का उपयोग क्षैतिज स्थानांतरित करने के लिए scrollview से बचने के लिए।

4

इस का सबसे अच्छा तरीका स्क्रॉल दिशा प्राप्त करने के लिए है, यह आप

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { 

    CGPoint targetPoint = *targetContentOffset; 
    CGPoint currentPoint = scrollView.contentOffset; 

    if (targetPoint.y > currentPoint.y) { 
     NSLog(@"up"); 
    } 
    else { 
     NSLog(@"down"); 
    } 
} 
संबंधित मुद्दे