贡献作者 -【XJDomain】
博客XJ: https://my.oschina.net/shengbingli/blog
GitHub直播地址: https://github.com/lishengbing/XJDomainLive
直接调用这个方法就可以,前提是资源包需要导入你的项目当中:
----资源包下载地址: https://github.com/lishengbing/XJDomainLive
----克隆上面项目: Classes -> OTher -> XJDomain.bundle包,直接拷贝到你的项目就可以使用了
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self praise];
}
- (void)praise{
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(kBounds.width - 60, kBounds.height - 49, 35, 35);
imageView.image = [UIImage imageNamed:@"heart"];
imageView.backgroundColor = [UIColor clearColor];
imageView.clipsToBounds = YES;
[self.view addSubview:imageView];
CGFloat startX = round(random() % 200);
CGFloat scale = round(random() % 2) + 1.0;
CGFloat speed = 1 / round(random() % 900) + 0.6;
int imageName = round(random() % 12);
NSLog(@"%.2f - %.2f -- %d",startX,scale,imageName);
[UIView beginAnimations:nil context:(__bridge void *_Nullable)(imageView)];
[UIView setAnimationDuration:7 * speed];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"XJDomain.bundle/heart%d.png",imageName]];
imageView.frame = CGRectMake(kBounds.width - startX, -100, 35 * scale, 35 * scale);
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (void)onAnimationComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
UIImageView *imageView = (__bridge UIImageView *)(context);
[imageView removeFromSuperview];
}
@end