Why does the CALayer animation work after loading the image, but not only after initialization?

I have a custom view (a small indicator obtained from UIViewwith a rotation animation) that has basically a heart icon ( UIImageView) in the middle and several balls (another UIImageView) rotating around it using the animation layer. Here is my code:

-(void)performInitialization{
    self.backgroundColor = [UIColor clearColor];
    CGRect frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
    [imageView setImage:[UIImage imageNamed:@"RedHeart"]];
    balls = [[UIImageView alloc] initWithFrame:frame];
    [balls setImage:[UIImage imageNamed:@"AngularBalls"]];
    [self addSubview:imageView];
    [self addSubview:balls];

    [balls.layer beginRotating];
}

... where my category CALayerdoes not have:

-(void)beginRotatingWithAngularVelocity:(float)velocity{
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rotationAnimation.fillMode = kCAFillModeForwards;
    rotationAnimation.removedOnCompletion = YES;
    rotationAnimation.repeatCount = 999999;
    rotationAnimation.duration = velocity;
    rotationAnimation.cumulative = YES;
    rotationAnimation.fromValue = [NSNumber numberWithFloat:0];
    rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2];
    [self addAnimation:rotationAnimation forKey:ROTATION_KEY];
}

-(void)beginRotating{
    [self beginRotatingWithAngularVelocity:0.7];
}

performInitialization init [WithFrame|WithCoder] . , . , . , . , , . , IB ( , , ), , ). ? nibs?

: . , , (, - - ). , , . , , -, . .

+3
1

. , ( didMoveToWindow). ( , / ).

+4

All Articles