Closed
Description
[CN]CYLTabBarController【一行代码实现 Lottie 动画 TabBar】
[EN]CYLTabBarController [An animated tabBar supported by Lottie with one line of code]
[CN]v1.24.1 版本添加了Lottie动画支持,可以最少添加一行代码,就可支持 Lottie 动画 TabBar: |
---|
[EN]In version of v1.24.1, CYLTabBarController supports to add animation of Lottie with one line of code. |
[CN]一行代码说明: 一个 TabBarItem 只设置一个键值 CYLTabBarLottieURL 即可支持。四个 TabBarItem 那就是四行代码。 |
---|
[EN]what does one line of code mean: If your TabBar is only conposed of one TabBarItem, you only need to assign a value to the key named CYLTabBarLottieURL . If it is conposed of four number of TabBarItems, you should add four lines of code. |
[CN]具体用法见: |
---|
[EN]How to use it: |
[CN]初始化时将以下两个值赋值即可: |
---|
[EN]Assign a values to keys listed here: |
[CN]对比 [EN]Comparation | key1 | key2 |
---|---|---|
key | CYLTabBarLottieURL |
CYLTabBarLottieSize |
type of value | NSURL |
NSValue |
meaning of value | [CN]lottie 所在路径 path of resource | [CN]LottieView大小 size of LottieView |
attention | [CN]必填 required | [CN]选填 [EN] optional |
other | [CN]根据此键值判断是否开启Lottie动画功能[EN]CYLTabBarController will evaluate in this key whether the animation should be added | [CN]选填,如果未传入了,会首先取 CYLTabBarItemImage 对应view的size,如果未传入,则会在内部取一个固定的缺省值。 [EN]This key is optional, if you donot assign any value to it, CYLTabBarController will try to assign the size of value of CYLTabBarItemImage . However if the value of CYLTabBarItemImage is null, CYLTabBarController will assign a default value to it. |
[CN]代码演示: |
---|
[EN]Show case: |
update Podfile
:
//Podfile
#pod 'CYLTabBarController', '~> 1.24.1' # [CN]默认不依赖Lottie [EN]Do not depend on lottie by default
pod 'CYLTabBarController/Lottie', '~> 1.24.1' # [CN]依赖Lottie库 [EN] Depend on lottie
code:
NSBundle *bundle = [NSBundle bundleForClass:[MainTabBarController class]];
NSDictionary *firstTabBarItemsAttributes = @{
CYLTabBarLottieURL : [NSURL fileURLWithPath:[bundle pathForResource:@"tab_home_animate" ofType:@"json"]],
// CYLTabBarLottieSize: [NSValue valueWithCGSize:CGSizeMake(22, 22)]//选填,设置LottieView大小
};
NSDictionary *secondTabBarItemsAttributes = @{
CYLTabBarLottieURL : [NSURL fileURLWithPath:[bundle pathForResource:@"tab_search_animate" ofType:@"json"]],
// CYLTabBarLottieSize: [NSValue valueWithCGSize:CGSizeMake(22, 22)]//选填,设置LottieView大小
};
NSArray *tabBarItemsAttributes = @[
firstTabBarItemsAttributes,
secondTabBarItemsAttributes,
];
CYLTabBarController *tabBarController = [CYLTabBarController tabBarControllerWithViewControllers:self.viewControllers
tabBarItemsAttributes:self.tabBarItemsAttributesForController
imageInsets:imageInsets
titlePositionAdjustment:titlePositionAdjustment
context:nil
];
Posted by Posted by 微博@iOS程序犭袁 & 公众号@iTeaTime技术清谈
原创文章,版权声明:自由转载-非商用-非衍生-保持署名 | Creative Commons BY-NC-ND 3.0
Activity
ChenYilong commentedon Apr 18, 2019
you can do like this:
do with the delegate :
you can find this delegate in demo file
AppDelegate.m
.[-]how to work with lottie[/-][+][CN]如何一行代码实现Lottie动画TabBar [EN]How to add animation of Lottie with one line of code[/+]LazyJiu commentedon Apr 19, 2019
后续集成势必要引入lottie,像我这种纯oc项目,140多m的,又不想使用lottie的,一旦引入swift就要超150m😂
HolmesZhao commentedon Apr 19, 2019
这个为了方便大佬可以单独写一个 category 么, 这样别的地方使用 lottie 的时候一行代码创建就好了😂 省的自己再写一份, 免得代码冗余
ChenYilong commentedon Apr 19, 2019
Lottie项目2.5.x之前用 Objective-C 实现的,之后的版本使用Swift实现的,目前CYLTabBarController依赖的是Objective-C版本。
ChenYilong commentedon Apr 20, 2019
Lottie官网有很多,动画文件,可以直接导出json,稍微改造下就能使用。
https://lottiefiles.com/recent
版权协议 https://lottiefiles.com/page/license
CC协议,(Creative Commons license)非常宽松
Files can be used for commercial usage within Applications
korea1501541730 commentedon Sep 29, 2019
XR iOS 13 release版本 动画一直刷CPU%。app直接挂了。又遇到的吗?
TzyTman commentedon Nov 7, 2019
OC版本库在哪里?
baishitong commentedon Jul 20, 2020
设置了 [self.cyl_tabBarController setSelectedIndex:2]; lottie动画的选中没有切换?
ChenYilong commentedon Jul 20, 2020
参照demo,要加延迟才行。
windforedawn commentedon Jan 20, 2021
您好,大牛,我想动态修改某个tabBarItem的lottie, 应该怎么做呢
yuyedaidao commentedon Mar 11, 2021
@windforedawn 有同样的疑问,不知道这个库还在维护吗