//联系人:石虎 QQ: 1224614774昵称:嗡嘛呢叭咪哄
/**
1.此方法很简单,有操作视图和方法,动画效果参考
2.图片下面有链接
3.GIF 图请看简书: http://www.jianshu.com/p/507d0722ce8c
*/
#import "SHViewController.h"
#define ANGLE_TO_RADIAN(angle) ((angle)/180.0 * M_PI)
@interface SHViewController ()
//图标
@property (weak,nonatomic)IBOutletUIImageView *iconView;
//开点按钮
- (IBAction)start;
//结束按钮
- (IBAction)end;
@end
@implementation CZViewController
- (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