1

画像ビューの 1 つの周りにグロー効果を生成する必要があります。そのために、shadowopacity プロパティを使用することにしました。

これが私のコードです:

imageViewForAnimation.layer.position = viewOrigin;
imageViewForAnimation.layer.shadowColor = [[UIColor yellowColor] CGColor];
imageViewForAnimation.layer.shadowOffset = CGSizeMake(0.0, 0.0);
imageViewForAnimation.layer.shadowRadius = 15.0;
imageViewForAnimation.layer.shadowOpacity = 0.3;
imageViewForAnimation.layer.masksToBounds = NO;
// Set up glow effect
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
anim.fromValue = [NSNumber numberWithFloat:0.0f];
anim.toValue = [NSNumber numberWithFloat:1.0f];
anim.duration = 3.0;
anim.repeatCount = HUGE_VALF;
anim.autoReverses = YES;
[imageViewForAnimation.layer addAnimation:anim forKey:@"shadowOpacity"];

imageViewForAnimation.layer.shadowPath = [UIBezierPath bezierPathWithRect:imageViewForAnimation.bounds].CGPath;

imageViewForAnimation.layer.shadowOpacity = 1.0f;   

ただし、アニメーションは一度実行すると停止します。繰り返しはありません。誰でも理由がわかりますか?

4

1 に答える 1

1

iOS 5 シミュレーターでコードを実行したところ、動作します。大文字の「R」があった唯一の問題

 anim.autoReverses= YES; 

正しいコード:

 anim.autoreverses= YES;

コードのスペルが正しい場合、アニメーションを追加する場所に問題がある可能性があります。私が言ったように、iOS 5 シミュレーターでコードを実行したところ、魅力的に動作しました。これが役に立ったことを願っています

于 2012-09-26T13:19:33.117 に答える