代わりに使用CABasicAnimation
アニメーションを、例えば、 のみアニメーション化する、shadowOpacity
uはuがアニメーション化コード
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//animation both the shadowOpacity and shadowRadius
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
CABasicAnimation *shadowRadiusAnimation = [CABasicAnimation animationWithKeyPath:@"shadowRadius" ];
shadowRadiusAnimation.fromValue =[NSNumber numberWithFloat:0.0];
shadowRadiusAnimation.toValue = [NSNumber numberWithFloat:20.0];
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[animation,shadowRadiusAnimation];
group.duration = 1.0f;
[cell.layer addAnimation:group forKey:@"shadowGroupAnimation"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
cell.layer.shadowOpacity = 1.0f;
cell.layer.shadowRadius = 20.0f;
}
下に使用することができshadowOpacity
とshadowRadius
両方をアニメーション化するコード
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//animation shadowOpacity
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
animation.duration = 1.0f;
[cell.layer addAnimation:animation forKey:@"shadowOpacityAnimation"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
cell.layer.shadowOpacity = 1.0f;
cell.layer.shadowRadius = 20.0f;
}
下に試みることができますshadowRadius
あなたは以下のコードを使用できます
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//animation shadowRadius
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CABasicAnimation *shadowRadiusAnimation = [CABasicAnimation animationWithKeyPath:@"shadowRadius" ];
shadowRadiusAnimation.fromValue =[NSNumber numberWithFloat:0.0];
shadowRadiusAnimation.toValue = [NSNumber numberWithFloat:20.0];
shadowRadiusAnimation.duration = 1.0f;
[cell.layer addAnimation:shadowRadiusAnimation forKey:@"shadowRadiusAnimation"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
cell.layer.shadowOpacity = 1.0f; //set final values
cell.layer.shadowRadius = 20.0f;
}
効果が編集
uはアニメーションデリゲートを設定することができ、このために仕上げた後、アニメーション をビューコントローラをプッシュし、アニメーションが完了した後、それが呼び出され、あまりにも異なる非常に類似していません。例えば
、
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//animation both the shadowOpacity and shadowRadius
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
CABasicAnimation *shadowRadiusAnimation = [CABasicAnimation animationWithKeyPath:@"shadowRadius" ];
shadowRadiusAnimation.fromValue =[NSNumber numberWithFloat:0.0];
shadowRadiusAnimation.toValue = [NSNumber numberWithFloat:20.0];
CAAnimationGroup *group = [CAAnimationGroup animation];
group.delegate = self; //this line set the delegate to self,
//if u use other option's also u can set the delegate for
//"CABasicAnimation" also just set it to self and implement the
// delegate method
group.animations = @[animation,shadowRadiusAnimation];
group.duration = 1.0f;
[cell.layer addAnimation:group forKey:@"shadowGroupAnimation"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
cell.layer.shadowOpacity = 1.0f;
cell.layer.shadowRadius = 20.0f;
}
//implement the delegate method this is called when animation stops with the flag,
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if(flag)
{
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
}
}
ありがとう!あなたのコードは機能します。上記のコードの直後に、私はnavigationControllerトランジションアニメーションを持っていますので、私も問題が見つかりました。それらを追加することによって、UITableViewCellが選択されたときにシャドーアニメーションが表示されなくなります。あなたは私が影をアニメーション化できるようにするために何をすべきかアドバイスできますか?その後、navigationControllerトランジションアニメーションが続きますか? – Calvin
これを最後の行に追加したとき:[self.navigationController pushViewController:_newViewController animated:YES];次に、影アニメーションを見ることができなくなり、画面は次のViewControllerに直接遷移します。 – Calvin
いいえ、シャドウアニメーションが完了したら、View Controllerをプッシュしたいですか? –