-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CN]如何一行代码实现Lottie动画TabBar [EN]How to add animation of Lottie with one line of code #341
Comments
you can do like this: do with the delegate : - (void)tabBarController:(UITabBarController *)tabBarController didSelectControl:(UIControl *)control {
/**
在选中tabbar的那个回调中,增加动画,
获取了UITabBarButton,
然后将动画的那个LOTAnimationView加在了UITabBarSwappableImageView的位置,
开始动画就隐藏了UITabBarSwappableImageView,
等动画完成了,就移除动画,显示UITabBarSwappableImageView
*/
} you can find this delegate in demo file #pragma mark - Tab Animation
- (void)showTabBarAnimation {
NSUInteger selectedIndex = self.selectedIndex ?: 0;
if (selectedIndex == self.lastAnimationIndex) {
return;
}
self.lastAnimationIndex = selectedIndex;
NSString *selectedTitle = [@[@"firstTab", @"secondTab", @"thirdTab"] objectAtIndex:selectedIndex];
NSArray *jsonRescources = @[@"lottie_tab_firstTab", @"lottie_tab_secondTab", @"lottie_tab_thirdTab"];
NSArray<UIView *> *views = self.tabBar.subviews;
for (int i = 0; i < views.count; i++) {
UIView *view = views[i];
if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
NSArray<UIView *> *subViews = view.subviews;
BOOL isSelected = NO;
UIView *animationView;
for (UIView *subView in subViews) {
if ([subView isKindOfClass:NSClassFromString(@"UITabBarButtonLabel")]) {
NSString *title = [subView valueForKey:@"text"];
isSelected = [selectedTitle isEqualToString:title];
} else if ([subView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
animationView = subView;
}
}
if (isSelected) {
animationView.hidden = YES;
//addAnimation
LOTAnimationView *animation = [LOTAnimationView animationNamed:[jsonRescources objectAtIndex:self.selectedIndex]];
animation.frame = animationView.frame;
[view addSubview:animation];
[animation playWithCompletion:^(BOOL animationFinished) {
animationView.hidden = NO;
[animation stop];
[animation removeFromSuperview];
}];
} else {
//remove animation
for (UIView *sub in view.subviews) {
if ([sub isKindOfClass:[LOTAnimationView class]]) {
[(LOTAnimationView *)sub stop];
[sub removeFromSuperview];
}
}
}
}
}
} |
后续集成势必要引入lottie,像我这种纯oc项目,140多m的,又不想使用lottie的,一旦引入swift就要超150m😂 |
这个为了方便大佬可以单独写一个 category 么, 这样别的地方使用 lottie 的时候一行代码创建就好了😂 省的自己再写一份, 免得代码冗余 |
Lottie项目2.5.x之前用 Objective-C 实现的,之后的版本使用Swift实现的,目前CYLTabBarController依赖的是Objective-C版本。 |
Lottie官网有很多,动画文件,可以直接导出json,稍微改造下就能使用。 版权协议 https://lottiefiles.com/page/license |
XR iOS 13 release版本 动画一直刷CPU%。app直接挂了。又遇到的吗? |
OC版本库在哪里? |
设置了 [self.cyl_tabBarController setSelectedIndex:2]; lottie动画的选中没有切换? |
参照demo,要加延迟才行。 |
您好,大牛,我想动态修改某个tabBarItem的lottie, 应该怎么做呢 |
@windforedawn 有同样的疑问,不知道这个库还在维护吗 |
[CN]CYLTabBarController【一行代码实现 Lottie 动画 TabBar】
[EN]CYLTabBarController [An animated tabBar supported by Lottie with one line of code]
CYLTabBarLottieURL
即可支持。四个 TabBarItem 那就是四行代码。CYLTabBarLottieURL
. If it is conposed of four number of TabBarItems, you should add four lines of code.CYLTabBarLottieURL
CYLTabBarLottieSize
NSURL
NSValue
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 ofCYLTabBarItemImage
. However if the value ofCYLTabBarItemImage
is null, CYLTabBarController will assign a default value to it.update
Podfile
:code:
Posted by Posted by 微博@iOS程序犭袁 & 公众号@iTeaTime技术清谈
原创文章,版权声明:自由转载-非商用-非衍生-保持署名 | Creative Commons BY-NC-ND 3.0
The text was updated successfully, but these errors were encountered: