- (void)tapAction:(UITapGestureRecognizer *)recognizer
{
// 取出手势的触摸点
CGPoint location = [recognizer locationInView:self.view];
// 1. 实例化动画组
CAAnimationGroup *group = [[CAAnimationGroupalloc]init];
CFTimeInterval duration = 2.0;
// 2. 定义动画组中的动画
// CAKeyframeAnimation *anim1 = [AnimationView moveRectWithDuration:duration from:self.myView.center to:location];
CAKeyframeAnimation *anim1 = [AnimationView moveWithDuration:duration from:self.myView.center to:location controlPointCount:4];
CABasicAnimation *anim2 = [AnimationView rotationWithDuration:duration from:0.0 to:2 * M_PI];
CABasicAnimation *scale = [AnimationView scaleWithDuration:duration from:2.0 to:0.5];
CABasicAnimation *opacity = [AnimationView opacityWithDuration:duration from:0.1 to:1.0];
// 3. 将定义的动画添加到动画组
[group setAnimations:@[anim1, anim2, scale, opacity]];
// 定义动画组执行的时间长度
[group setDuration:duration];
// 5) 设置键值记录目标位置,以便动画结束后,修正位置
// 并不是所有的动画方法都需要设置目标点
[group setValue:@"translationTo"forKey:@"animationType"];
[group setValue:[NSValuevalueWithCGPoint:location] forKey:@"targetPoint"];
[group setDelegate:self];
// 4. 将动画组添加到视图的图层
[self.myView.layer addAnimation:group forKey:nil];
}