首先我们用pod安装2个三方库:
use_frameworks! target ‘Love--动画‘ do pod ‘pop‘, ‘~> 1.0.9‘ pod ‘POP+MCAnimate‘, ‘~> 2.0‘ end
实现代码:
#import "RootViewController.h" @interface RootViewController () @property (nonatomic, strong) UIImageView *myImageView; @property (nonatomic, strong) dispatch_source_t timer; @end @implementation RootViewController - (void)viewWillAppear:(BOOL)animated { [self setupScoreAnimation]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; self.title = @"臭美"; self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 300, 100, 100)]; UIImage *image = [UIImage imageNamed:@"10"]; self.myImageView.layer.cornerRadius = 50; self.myImageView.layer.masksToBounds = YES; self.myImageView.image = image; [self.view addSubview:_myImageView]; } - (void)setupScoreAnimation { dispatch_queue_t queue = dispatch_get_main_queue(); self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)); uint64_t interval = (uint64_t)(1.0 * NSEC_PER_SEC); dispatch_source_set_timer(self.timer, start, interval, 0); dispatch_source_set_event_handler(self.timer, ^{ [self animationStar]; }); dispatch_resume(self.timer); } - (void)animationStar { [NSObject pop_animate:^{ self.myImageView.pop_spring.pop_scaleXY = CGPointMake(1.5, 1.5); self.myImageView.pop_springBounciness = 20; self.myImageView.pop_springSpeed = 20; } completion:^(BOOL finished) { self.myImageView.pop_spring.pop_scaleXY = CGPointMake(1, 1); self.myImageView.pop_springBounciness = 20; self.myImageView.pop_springSpeed = 20; }]; } @end
自己可以试试哈...
记得要将timer至nil啊.
- (void)viewDidDisappear:(BOOL)animated { dispatch_cancel(self.timer); self.timer = nil; }
完成...
时间: 2024-10-05 16:55:53