2012-12-03 15 views
5

में सभी UICollectionViewCells को एनिमेट करना मैं सोच रहा था कि UICollectionView में सभी कक्षों को एनिमेट करने का एक अच्छा तरीका क्या है। मैं एक UICollectionView में संपादन अनुकरण करने की कोशिश कर रहा हूँ। तो मैं क्या करना चाहता हूं UICollectionViewCells की सभी सीमाओं को कम करना है। तो क्या मैं यह है:एक UICollectionView

- (IBAction)startEditingMode:(id)sender { 
    [_items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; 
     UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; 

     [UIView animateWithDuration:0.25 animations:^{ 
      cell.layer.transform = CATransform3DMakeScale(0.9, 0.9, 1); 
     }]; 
    }]; 
} 

यह काम करता है, लेकिन मुझे यकीन है कि अगर वहाँ UICollectionView पर एक संपत्ति, या इस तरह कुछ करने के लिए एक बेहतर और अधिक मानक तरीका था नहीं था। धन्यवाद।

उत्तर

0

क्या आपने UICollectionView performBatchUpdates: का उपयोग करने का प्रयास किया है?

कुछ की तरह:

[collectionView performBatchUpdates:^{ 
    [_items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; 
     UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; 
     cell.layer.transform = CATransform3DMakeScale(0.9, 0.9, 1); 
    }]; 
} completion:^{}]; 
1

मैं एक UICollectionViewLayout उपवर्ग पैदा करेगा। संपादन नामक एक बूल संपत्ति जोड़ें। परिवर्तनों को संपादित करते समय, अमान्य Layout पर कॉल करें। फिर -layoutAttributesForItemAtIndexPath द्वारा लौटाए गए गुण में: विधि आप एक ट्रांसफॉर्म निर्दिष्ट कर सकते हैं।

आपके दृष्टिकोण के साथ समस्या यह है कि यह केवल दृश्यमान कोशिकाओं को प्रभावित करता है। UICollectionViewLayout सबक्लास अच्छा है क्योंकि यह सभी कोशिकाओं में परिवर्तन को लागू करेगा, भले ही नए जोड़े जाएंगे। और यह दृश्य नियंत्रक से बाहर सभी संग्रह दृश्य लेआउट हैंडलिंग चलाता है।

सेल विशेषताओं में फ्रेम, आकार, केंद्र, परिवर्तन (3 डी), अल्फा, और अपने स्वयं के कस्टम विशेषताओं शामिल हो सकते हैं।

आप wL_ द्वारा सुझाए गए अनुसार, एक -performBatchUpdates: ब्लॉक में संपादन का मूल्य बदल देंगे।

- (IBAction)startEditingMode:(id)sender { 
    [self.collectionView performBatchUpdates:^{ 
     ((MyCollectionViewLayout *)self.collectionView.collectionViewLayout).editing = YES; 
    } 
    completion:NULL]; 
} 

और UICollectionViewLayout उपवर्ग में:

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 

    if (self.editing) { 
     attributes.transform = CGAffineTransformMakeScale(0.9, 0.9); 
    } 
    else { 
     attributes.transform = CGAffineTransformIdentity; 
    } 

    return attributes; 
} 

यह भी ध्यान रखें कि आप (शायद) एक 3 डी यहाँ बदलने की जरूरत नहीं है। एक affine परिवर्तन पर्याप्त है।

संबंधित मुद्दे