CAniamtion 基本使用
CAAnimation(抽象)<NSCoding, NSCopying, CAMediaTiming, CAAction>
QuartzCore框架的基本继承结构
-> CATransition
CAAnimation(抽象) -> CAPropertyAnimation -> CABasicAnimation
-> CAKeyframeAnimation
-> CAAnimationGroup
//渐变 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"];
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步