Sto provando a creare una sequenza di animazioni, ho trovato in CAAnimationGroup
la classe giusta per ottenere quell'oggetto. In pratica sto aggiungendo in una vista diverse sottoview e mi piacerebbe animare la loro entrata con un effetto di rimbalzo, il fatto è che voglio vedere le loro animazioni accadere subito dopo che il precedente è finito. So che posso impostare il delegato, ma ho pensato che lo CAAnimationGroup
fosse la scelta giusta.
Successivamente ho scoperto che l'animazione di gruppo può appartenere solo a un livello, ma ne ho bisogno su diversi livelli sullo schermo. Ovviamente sul livello di hosting non funziona. Alcuni suggerimenti?Animazione sequenza utilizzando CAAnimationGroup
- (void) didMoveToSuperview {
[super didMoveToSuperview];
float startTime = 0;
NSMutableArray * animArray = @[].mutableCopy;
for (int i = 1; i<=_score; i++) {
NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject: self.greenLeaf];
UIImageView * greenLeafImageView = [NSKeyedUnarchiver unarchiveObjectWithData: archivedData];
greenLeafImageView.image = [UIImage imageNamed:@"greenLeaf"];
CGPoint leafCenter = calculatePointCoordinateWithRadiusAndRotation(63, -(M_PI/11 * i) - M_PI_2);
greenLeafImageView.center = CGPointApplyAffineTransform(leafCenter, CGAffineTransformMakeTranslation(self.bounds.size.width/2, self.bounds.size.height));
[self addSubview:greenLeafImageView];
//Animation creation
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
greenLeafImageView.layer.transform = CATransform3DIdentity;
bounceAnimation.values = @[
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:1.1],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0]
];
bounceAnimation.duration = 2;
bounceAnimation.beginTime = startTime;
startTime += bounceAnimation.duration;
[animArray addObject:bounceAnimation];
//[greenLeafImageView.layer addAnimation:bounceAnimation forKey:nil];
}
// Rotation animation
[UIView animateWithDuration:1 animations:^{
self.arrow.transform = CGAffineTransformMakeRotation(M_PI/11 * _score);
}];
CAAnimationGroup * group = [CAAnimationGroup animation];
group.animations = animArray;
group.duration = [[ animArray valueForKeyPath:@"@sum.duration"] floatValue];
[self.layer addAnimation:group forKey:nil];
}
Ottimo, grazie !!! – Andrea