2010-11-25 13 views

答えて

2

このようなことを試してみてください。

- (void)spinButton 
{ 
    [CATransaction begin]; 
    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 
    CGRect frame = [button frame]; 
    button.layer.anchorPoint = CGPointMake(0.5, 0.5); 
    button.layer.position = CGPointMake(frame.origin.x + 0.5 * frame.size.width, frame.origin.y + 0.5 * frame.size.height); 
    [CATransaction commit]; 

    [CATransaction begin]; 
    [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions]; 
    [CATransaction setValue:[NSNumber numberWithFloat:2.0] forKey:kCATransactionAnimationDuration]; 

    CABasicAnimation *animation; 
    animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
    animation.fromValue = [NSNumber numberWithFloat:0.0]; 
    animation.toValue = [NSNumber numberWithFloat:2 * M_PI]; 
    animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear]; 
    animation.delegate = self; 
    [button.layer addAnimation:animation forKey:@"rotationAnimation"]; 

    [CATransaction commit]; 
} 

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)finished 
{ 
    if (finished) 
    { 
     [self spinButton]; 
    } 
} 

- (void)setButtonImage:(UIImage *)image 
{ 
    [button.layer removeAllAnimations]; 
    if (!image) 
    { 
     [button setImage:[UIImage imageNamed:@"playbutton.png"] forState:0]; 
    } 
    else 
    { 
     [button setImage:image forState:0]; 

     if ([button.currentImage isEqual:[UIImage imageNamed:@"loadingbutton.png"]]) 
     { 
      [self spinButton]; 
     } 
    } 
} 
のようなものを呼び出すことによって、アニメーションを終了
関連する問題