Note that there are some explanatory texts on larger screens.

plurals
  1. POSequence animation using CAAnimationGroup
    primarykey
    data
    text
    <p>I'm trying to make a sequence of animations, I've found in <code>CAAnimationGroup</code> the right class to achieve that object. In practice I'm adding on a view different subviews and I'd like to animate their entry with a bounce effect, the fact is that I want to see their animations happening right after the previous has finished. I know that I can set the delegate, but I thought that the <code>CAAnimationGroup</code> was the right choice. <br> Later I discovered that the group animation can belong only to one layer, but I need it on different layers on screen. Of course on the hosting layer doesn't work. Some suggestions?</p> <pre><code>- (void) didMoveToSuperview { [super didMoveToSuperview]; float startTime = 0; NSMutableArray * animArray = @[].mutableCopy; for (int i = 1; i&lt;=_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]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload