重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍了iOS开发中如何仿Tumblr点赞心破碎动画效果,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
成都创新互联专注于企业成都全网营销、网站重做改版、于洪网站定制设计、自适应品牌网站建设、H5高端网站建设、商城网站开发、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为于洪等各大城市提供网站开发制作服务。1.首先看下效果:
2.模仿Tumblr中的效果应用如下:
原理:使用按钮点击Action增加两个事件,通过改变背景hidden和frame,切换图片,增加动画效果等;
setupUI及touch Action:
- (void)setupUI
{
// 点击的btn
UIButton *praiseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
praiseBtn.frame = CGRectMake(100, 200, KKPraiseBtnWH, KKPraiseBtnWH);
[praiseBtn setImage:[UIImage imageNamed:@"icon_like"] forState:UIControlStateNormal];
[praiseBtn setImage:[UIImage imageNamed:@"icon_likeon"] forState:UIControlStateSelected];
[self.view addSubview:praiseBtn];
[praiseBtn addTarget:self action:@selector(clickTheBtn:) forControlEvents:UIControlEventTouchUpInside];
_praiseBtn = praiseBtn;
// 放大后的btn
_coverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_coverBtn.frame = praiseBtn.frame;
_coverBtn.alpha = 0;
[_coverBtn setImage:[UIImage imageNamed:@"big"] forState:UIControlStateSelected];
[_coverBtn setImage:[UIImage imageNamed:@"big"] forState:UIControlStateNormal];
[self.view insertSubview:_coverBtn belowSubview:praiseBtn];
_cancelPraiseImg = [[UIImageView alloc]initWithFrame:CGRectMake(80, 150, KKPraiseBtnWH*2, KKPraiseBtnWH*2*KKToBrokenHeartWH)];
_cancelPraiseImg.hidden = YES;
_cancelPraiseImg.centerX = _praiseBtn.centerX;
[self.view addSubview:_cancelPraiseImg];
}
-(void)clickTheBtn:(UIButton *)btn
{
[self playAnimation];
btn.userInteractionEnabled = NO;
btn.selected = !btn.selected;
}
-(void)playAnimation{
if (!_praiseBtn.selected) {
_coverBtn.alpha = 1;
[UIView animateWithDuration:1.0f animations:^{
_coverBtn.frame = CGRectMake(80, 100, KKPraiseBtnWH*2, KKPraiseBtnWH*2);
CAKeyframeAnimation *anima = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
NSValue *value1 = [NSNumber numberWithFloat:-M_PI/180*5];
NSValue *value2 = [NSNumber numberWithFloat:M_PI/180*5];
NSValue *value3 = [NSNumber numberWithFloat:-M_PI/180*5];
anima.values = @[value1,value2,value3];
anima.repeatCount = MAXFLOAT;
[_coverBtn.layer addAnimation:anima forKey:nil];
_coverBtn.alpha = 0;
_coverBtn.centerX = _praiseBtn.centerX;
} completion:^(BOOL finished) {
_coverBtn.frame = _praiseBtn.frame;
_praiseBtn.userInteractionEnabled = YES;
}];
} else {
_cancelPraiseImg.hidden = NO;
NSArray *imgArr = [NSArray arrayWithObjects:[UIImage imageNamed:@"icon_like_broken1"],[UIImage imageNamed:@"icon_like_broken2"],[UIImage imageNamed:@"icon_like_broken3"],[UIImage imageNamed:@"icon_like_broken4"], nil nil];
_cancelPraiseImg.animationImages = imgArr;
_cancelPraiseImg.animationDuration = KKBorkenTime;
_cancelPraiseImg.animationRepeatCount = 1;
[_cancelPraiseImg startAnimating];
[UIView animateWithDuration:KKBorkenTime animations:^{
_cancelPraiseImg.frame = CGRectMake(80, 200, KKPraiseBtnWH*2, KKPraiseBtnWH*2*KKToBrokenHeartWH);
_cancelPraiseImg.alpha = 0;
}completion:^(BOOL finished) {
_cancelPraiseImg.frame = CGRectMake(80, 150, KKPraiseBtnWH*2, KKPraiseBtnWH*2*KKToBrokenHeartWH);
_cancelPraiseImg.alpha = 1;
_praiseBtn.userInteractionEnabled = YES;
}];
}
}
感谢你能够认真阅读完这篇文章,希望小编分享的“iOS开发中如何仿Tumblr点赞心破碎动画效果”这篇文章对大家有帮助,同时也希望大家多多支持创新互联建站,关注创新互联网站建设公司行业资讯频道,更多相关知识等着你来学习!
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。