आप परत की गति संपत्ति सेट कर सकते हैं (जैसे [रोटोवा के उत्तर]) (https://stackoverflow.com/a/23146861/5271393) नियंत्रण को एनीमेशन की गति को बदलने के लिए। समस्या यह है कि आप मनमानी मानों का उपयोग कर रहे हैं क्योंकि आप सम्मिलन एनीमेशन की वास्तविक अवधि नहीं जानते हैं।
this post का उपयोग करके आप यह पता लगा सकते हैं कि डिफ़ॉल्ट एनीमेशन अवधि क्या है।
newAnimationDuration = (1/layer.speed)*originalAnimationDuration
layer.speed = originalAnimationDuration/newAnimationDuration
यदि आप अपने लेआउट तुम में, एनीमेशन 400 मि.से लंबे बनाना चाहते थे:
- (UICollectionViewLayoutAttributes *)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes* attributes = [super finalLayoutAttributesForDisappearingItemAtIndexPath:indexPath];
//set attributes here
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
CGFloat originalAnimationDuration = [CATransaction animationDuration];
CGFloat newAnimationDuration = 0.4f;
cell.layer.speed = originalAnimationDuration/newAnimationDuration;
return attributes;
}
मेरे मामले मैं कोशिकाओं जो बंद स्क्रीन घसीटा जा सकता था और मैं की अवधि को बदलना चाहते हैं पैन इशारा की गति के आधार पर हटाने की एनीमेशन।
इशारा पहचानकर्ता में (जो अपने संग्रह को देखने के हिस्सा होना चाहिए):
- (void)handlePanGesture:(UIPanGestureRecognizer *)sender
{
CGPoint dragVelocityVector = [sender velocityInView:self.collectionView];
CGFloat dragVelocity = sqrt(dragVelocityVector.x*dragVelocityVector.x + dragVelocityVector.y*dragVelocityVector.y);
switch (sender.state) {
...
case UIGestureRecognizerStateChanged:{
CustomLayoutClass *layout = (CustomLayoutClass *)self.collectionViewLayout;
layout.dragSpeed = fabs(dragVelocity);
...
}
...
}
फिर अपने customLayout में:
- (UICollectionViewLayoutAttributes *)finalLayoutAttributesForDisappearingItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes* attributes = [super finalLayoutAttributesForDisappearingItemAtIndexPath:indexPath];
CGFloat animationDistance = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
CGFloat originalAnimationDuration = [CATransaction animationDuration];
CGFloat newAnimationDuration = animationDistance/self.dragSpeed;
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
cell.layer.speed = originalAnimationDuration/newAnimationDuration;
return attributes;
}
एप्पल के प्रलेखन अनुसार, अब मान्य नहीं है "जब लेआउट परिवर्तन एनिमेट, एनीमेशन समय और मानकों संग्रह दृश्य द्वारा नियंत्रित कर रहे हैं।" यह setCollectionView के संदर्भ में है: एनिमेटेड: विधि, लेकिन मुझे संदेह है कि संग्रह दृश्य की सीमाओं को संशोधित करने के लिए भी यही सच है। क्षमा करें मैं और मदद नहीं कर सकता, मैं एक ही समस्या पर फंस गया हूँ। मुझे संदेह है कि उत्तर UICollectionView ऑब्जेक्ट के भीतर कहीं भी स्थित है। – Ash