//渐变 UIButton *b = (UIButton *)sender; CATransition *transition = [CATransition animation]; transition.type = kCATransitionPush; transition.subtype = kCATransitionFromRight; [self.imageview.layer addAnimation:transition forKey:@"transition"]; self.imageview.image = [UIImage imageNamed:@"avatar.jpg"]; //基本 CABasicAnimation *baseProperty = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; baseProperty.fromValue = [NSNumber numberWithDouble:1.0]; baseProperty.toValue = [NSNumber numberWithDouble:0.4]; baseProperty.duration = 1.0; baseProperty.removedOnCompletion = NO; baseProperty.fillMode = kCAFillModeForwards; baseProperty.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; [self.imageview.layer addAnimation:baseProperty forKey:@"baseProperty"]; //关键帧 //动画组 CAKeyframeAnimation *keyFrameAniamtion = [CAKeyframeAnimation animationWithKeyPath:@"position"]; CGMutablePathRef mutablePath = CGPathCreateMutable(); CGPathMoveToPoint(mutablePath, NULL, self.imageview.frame.origin.x, self.imageview.frame.origin.y); CGPathAddLineToPoint(mutablePath, NULL, 0, 0); keyFrameAniamtion.path = mutablePath; keyFrameAniamtion.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; CAKeyframeAnimation *keyframe2 = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"]; NSArray *values2 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0], [NSNumber numberWithFloat:(M_PI * 10)], nil]; keyframe2.values = values2; keyframe2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; CAAnimationGroup *group = [CAAnimationGroup animation]; group.removedOnCompletion = NO; group.fillMode = kCAFillModeForwards; group.animations = [NSArray arrayWithObjects:keyFrameAniamtion, keyframe2, nil]; group.duration = 2.0; [self.imageview.layer addAnimation:group forKey:@"group"];
时间: 2024-11-03 22:34:58