//联系人:石虎QQ: 1224614774昵称:嗡嘛呢叭咪哄
实现效果:
实现技术过程:
#import"SHViewController.h"
#define ANGLE_TO_RADIAN(angle) ((angle)/180.0* M_PI)
@interfaceSHViewController()
//图标
@property(weak,nonatomic)IBOutletUIImageView*iconView;
//开点按钮
- (IBAction)start;
//结束按钮
- (IBAction)end;
@end
@implementationCZViewController
- (void)viewDidLoad
{
[superviewDidLoad];
}
//开点按钮功能呢
- (IBAction)start {
//实例化
CAKeyframeAnimation*anim = [CAKeyframeAnimationanimation];
//拿到动画key
anim.keyPath=@"transform.rotation";
//动画时间
anim.duration=.25;
//重复的次数
//anim.repeatCount = 16;
//无限次重复
anim.repeatCount=MAXFLOAT;
//设置抖动数值
anim.values=@[@(ANGLE_TO_RADIAN(-5)),@(ANGLE_TO_RADIAN(5)),@(ANGLE_TO_RADIAN(-5))];
//保持最后的状态
anim.removedOnCompletion=NO;
//动画的填充模式
anim.fillMode=kCAFillModeForwards;
//layer层实现动画
[self.iconView.layeraddAnimation:animforKey:@"shake"];
}
//点击结束按钮
- (IBAction)end {
//图标
[self.iconView.layerremoveAnimationForKey:@"shake"];
}
@end