萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> ios >> 仿iOS圖標抖動

仿iOS圖標抖動

   最近閒來無聊,研究了一下IPhone桌面圖標的抖動,網上有一個類似的事例,但是我看來效果實在不佳,自己也來寫一個玩玩,有需要的小伙伴可以參考下。

  仿iOS圖標抖動

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #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

  以上所述就是本文的全部內容了,希望大家能夠喜歡。

copyright © 萬盛學電腦網 all rights reserved