2013-03-24 11 views
5

क्यों लौटाता है मेरे पास UICollectionViewUIViewController में निहित है जो क्षैतिज UICollectionViewFlowLayout का उपयोग करता है। मैं अपने UIStoryboard में बनाए गए प्रोटोटाइप सेल का भी उपयोग कर रहा हूं। मैं एक कस्टम पेजिंग बनाना चाहता हूं, इसलिए मैं - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset का उपयोग कर रहा हूं।indexPathForItemAtPoint हमेशा शून्य

समस्या यह है कि हर बार जब मैं 0Cको लक्ष्यकंटऑफसेट (स्क्रॉल दृश्य में बिंदु जहां स्क्रॉल रुक जाएगा) के अनुरूप प्राप्त करने का प्रयास कर रहा हूं, तो संग्रह दृश्य शून्य में वापस आता है भले ही बिंदु संग्रह के अंदर स्पष्ट रूप से हो सामग्री आकार देखें।

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset 
{ 
    NSIndexPath *indexPath = [_collectionView indexPathForItemAtPoint:(*targetContentOffset)]; 
    // Do something with indexPath  
} 

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

+0

आप इवर क्यों प्रयोग कर रहे हैं? जांचें कि '_collectionView' स्वयं पहले शून्य है या नहीं। – 7usam

+0

मैंने scrollView चर का उपयोग करने का प्रयास किया है लेकिन परिणाम वही है। जब मैं विधि को कॉल करता हूं तो मैं सकारात्मक नहीं हूं। – DrMonkey68

उत्तर

0

संग्रह दृश्य अभी तक targetContentOffset के लिए indexPath नहीं जानता है।

आपको संग्रह की पूछताछ करने के लिए आपको ViewLayout से पूछना होगा जो इस स्थिति में लेआउट होगा।

इस तरह की कोशिश कुछ:

UICollectionViewLayoutAttributes *attribute = [_collectionView.collectionViewLayout layoutAttributesForElementsInRect:(CGRect){(*targetContentOffset).x, 0, 10, self.collectionView.bounds.size.height}][0]; 
संबंधित मुद्दे