您的位置:首页 > 移动开发 > IOS开发

IOS第18天(7,CAKeyframeAnimation-图标抖动)

2015-09-06 17:29 495 查看
***

#import "HMViewController.h"

#define angle2radian(x) ((x) / 180.0 * M_PI)

@interface HMViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation HMViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

[_imageView addGestureRecognizer:longPress];
}

- (void)longPress:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan) {

CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

anim.keyPath = @"transform.rotation";

anim.values = @[@(angle2radian(-5)),@(angle2radian(5)),@(angle2radian(-5))];

anim.repeatCount = MAXFLOAT;

anim.duration = 0.5;

[_imageView.layer addAnimation:anim forKey:nil];

}
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: