利用UIBezierPath和@"strokeEnd",@"strokeStart"绘制tabbar动画样式的选中

自己项目中自定义的UITabbar,选中后有路径的过度,效果图为

动画实现的核心代码为

1.第一步

 [animationPath addArcWithCenter:center1 radius:RADIUS startAngle:M_PI_2-0.001 endAngle:M_PI*2+M_PI_2 clockwise:clockwise];
    [animationPath addArcWithCenter:center2 radius:RADIUS startAngle:M_PI_2-0.001 endAngle:M_PI*2+M_PI_2 clockwise:clockwise];

这里根据点击的前后不同tabbaritem的中心位置,描绘了两段圆弧,然后这段路径给自定义tabbarView的layer,这里两段圆弧的终点和起点会自动使用直线连接,参考说明有(https://www.jianshu.com/p/5e96e754d9cb

 

2.绘制起点到终点的线段,代码实现为

CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

 strokeEndAnimation.duration = 0.4; 

 strokeEndAnimation.fromValue = @0;

 strokeEndAnimation.toValue = @1;

然后还伴随着线段的消失,代码的实现为

CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];

 strokeStartAnimation.duration = strokeEndAnimation.duration - 0.15;

 strokeStartAnimation.removedOnCompletion = clockwise;

 strokeStartAnimation.fillMode =kCAFillModeForwards;

 strokeStartAnimation.fromValue = @0;

 strokeStartAnimation.toValue = @(1-(s/length));

关于核心动画strokeEnd和strokeStart的使用参见资料有(https://www.jianshu.com/p/e95c79327fe3)以及(https://blog.csdn.net/u014745414/article/details/44785623?locationNum=10&fps=1)  个人理解是一个负责线段出现,一个是线段的消失

3.最后在动画结束的代理方法里面切换选中的tabbaritem,显示完美衔接,代码为 

 self.superview.userInteractionEnabled = YES;

 WGTabBarItem *tapItem = (WGTabBarItem *)[self viewWithTag:_selectIndex + ITEMTAG];

 tapItem.isSelect = YES;

 tapItem.titleLab.textColor = _tintColor;

 _tabBarItem = tapItem;

附上个人github上的代码(https://github.com/xc19930909yu/CustomTabbar

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值