tl; डॉ: अगर मैं अपने व्याकरण में कुछ गलतियां मैं अंग्रेज़ी नहीं, माफी चाहता हूँ आप मैन्युअल रूप से पिछले खत्म होने के बाद प्रत्येक एनीमेशन जोड़ने की जरूरत है।
अनुक्रमिक एनिमेशन जोड़ने के लिए कोई भी तरीका नहीं बनाया गया है। आप प्रत्येक एनीमेशन की देरी को पिछले सभी एनिमेशनों का योग निर्धारित करने के लिए सेट कर सकते हैं लेकिन मैं इसकी अनुशंसा नहीं करता।
इसके बजाय मैं सभी एनिमेशन बनाउंगा और उन्हें एक म्यूटेबल सरणी (सरणी के रूप में सरणी का उपयोग करके) में क्रमबद्ध करने के क्रम में जोड़ दूंगा। फिर अपने आप को एनीमेशन के रूप में सेट करके सभी एनिमेशन में प्रतिनिधि को animationDidStop:finished:
कॉलबैक प्राप्त हो सकता है जब भी कोई एनीमेशन समाप्त हो जाता है।
उस विधि में आप सरणी से पहली एनीमेशन (अगली एनीमेशन का अर्थ) हटा देंगे और इसे परत में जोड़ देंगे। चूंकि आप प्रतिनिधि हैं, इसलिए आपको दूसरी एनीमेशन मिल जाएगी जब वह एक स्थिति में animationDidStop:finished:
कॉलबैक फिर से चलाएगा और अगली एनीमेशन को म्यूटेबल सरणी से हटा दिया जाएगा और परत में जोड़ा जाएगा।
एक बार एनिमेशन की सरणी खाली हो जाने पर, सभी एनिमेशन चलेंगे।
कुछ नमूना कोड शुरू करने के लिए। सबसे पहले आप अपने सभी एनिमेशन की स्थापना:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
[animation setToValue:(id)[[UIColor redColor] CGColor]];
[animation setDuration:1.5];
[animation setDelegate:self];
[animation setValue:[view layer] forKey:@"layerToApplyAnimationTo"];
// Configure other animations the same way ...
[self setSequenceOfAnimations:[NSMutableArray arrayWithArray: @[ animation, animation1, animation2, animation3, animation4, animation5 ] ]];
// Start the chain of animations by adding the "next" (the first) animation
[self applyNextAnimation];
तब प्रतिनिधि कॉलबैक में आप बस अगले एनीमेशन लागू फिर
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished {
[self applyNextAnimation];
}
- (void)applyNextAnimation {
// Finish when there are no more animations to run
if ([[self sequenceOfAnimations] count] == 0) return;
// Get the next animation and remove it from the "queue"
CAPropertyAnimation * nextAnimation = [[self sequenceOfAnimations] objectAtIndex:0];
[[self sequenceOfAnimations] removeObjectAtIndex:0];
// Get the layer and apply the animation
CALayer *layerToAnimate = [nextAnimation valueForKey:@"layerToApplyAnimationTo"];
[layerToAnimate addAnimation:nextAnimation forKey:nil];
}
मैं ताकि प्रत्येक एनीमेशन इसकी परत जानता है एक कस्टम कुंजी layerToApplyAnimationTo
उपयोग कर रहा हूँ (यह केवल setValue:forKey:
और valueForKey:
द्वारा काम करता है)।
स्रोत
2012-07-31 11:09:20
आप और अधिक उन्नत करने के लिए एनिमेशन के साथ-साथ या केवल आगे बढ़, स्केलिंग और (3 डी नहीं) घूर्णन का इरादा है? –
हां, मैं भी CATransform3DMakeRotation और अन्य – torhector2