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

仿iOS中图标的抖动

时间:2015-04-11 14:58:06      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

#import "LHViewController.h"
#define angelToRandian(x)  ((x)/180.0*M_PI)
@interface LHViewController ()
@property (strong, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation LHViewController

- (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:)];
    [self.imageView addGestureRecognizer:longPress];
}

-(void)longPress:(UILongPressGestureRecognizer*)longPress
{
    if (longPress.state==UIGestureRecognizerStateBegan) {
        CAKeyframeAnimation* anim=[CAKeyframeAnimation animation];
        anim.keyPath=@"transform.rotation";
        anim.values=@[@(angelToRandian(-7)),@(angelToRandian(7)),@(angelToRandian(-7))];
        anim.repeatCount=MAXFLOAT;
        anim.duration=0.2;
        [self.imageView.layer addAnimation:anim forKey:nil];
        self.btn.hidden=NO;
    }
}

- (IBAction)delete:(id)sender {
    [self.imageView removeFromSuperview];
    [self.btn removeFromSuperview];
}
@end

以下是程序运行的结果:

技术分享

技术分享


仿iOS中图标的抖动

标签:

原文地址:http://my.oschina.net/iOSliuhui/blog/398897

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