码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-09-06 18:21:56      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

***

#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

 

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

标签:

原文地址:http://www.cnblogs.com/ios-g/p/4786722.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!