Copy iOS icon jitter

  • 2020-05-06 11:42:52
  • OfStack

Copy iOS icon jitter


#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

The above is all the content of this article, I hope you can enjoy it.


Related articles: