//
// ViewController.m
// 图标抖动
//
// Created by Mac on 16/1/11.
// Copyright © 2016年 Mac. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *
imageView;
@end
@implementation ViewController
- (
void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-
(IBAction)startAnimation {
CAKeyframeAnimation *rotationAni =
[CAKeyframeAnimation animation];
rotationAni.keyPath =
@"transform.rotation";
// 计算旋转的弧度
CGFloat angle = M_PI_4 *
0.1;
// 设置旋转的路径
rotationAni.values = @[@(-angle),@(angle),@(-
angle)];
rotationAni.duration =
0.2;
rotationAni.repeatCount =
MAXFLOAT;
[self.imageView.layer addAnimation:rotationAni forKey:@"shake"];
}
-
(IBAction)endAnimation {
// 通过key 移除动画
[self.imageView.layer removeAnimationForKey:
@"shake"];
}
- (
void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
转载于:https://www.cnblogs.com/BJTUzhengli/p/5121881.html
相关资源:IOS核心动画-左右摆动Demo