Skip to content

Commit

Permalink
fix: v1.28.5 key icon center without title, edit shadow appearance in…
Browse files Browse the repository at this point in the history
… iOS13

fix issues:
#431
#436
#492
#423
  • Loading branch information
ChenYilong committed May 5, 2020
1 parent 8f37d51 commit 2eaabd6
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 72 deletions.
2 changes: 1 addition & 1 deletion CYLTabBarController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CYLTabBarController"
s.version = "1.28.5"
s.version = "1.29.0"
s.summary = "Highly customizable tabBar and tabBarController for iOS"
s.description = "[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS12 & iPhone XS MAX supported】"
s.homepage = "https://github.com/ChenYilong/CYLTabBarController"
Expand Down
25 changes: 21 additions & 4 deletions CYLTabBarController/CYLTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ @interface CYLTabBarController () <UITabBarControllerDelegate>
@property (nonatomic, strong) NSMutableArray<NSURL *> *lottieURLs;
@property (nonatomic, strong) NSMutableArray *lottieSizes;
@property (nonatomic, assign, getter=isLottieViewAdded) BOOL lottieViewAdded;
@property (nonatomic, strong) UIImage *tabItemPlaceholderImage;

@end

Expand Down Expand Up @@ -91,6 +92,8 @@ - (void)viewDidLayoutSubviews {
if ([control cyl_isChildViewControllerPlusButton]) {
return;
}
UILabel *tabLabel = control.cyl_tabLabel;
tabLabel.textAlignment = NSTextAlignmentCenter;
SEL actin = @selector(didSelectControl:);
[control addTarget:self action:actin forControlEvents:UIControlEventTouchUpInside];
if (idx == self.selectedIndex && ![control isKindOfClass:[CYLPlusButton class]]) {
Expand Down Expand Up @@ -433,6 +436,21 @@ - (void)setTintColor:(UIColor *)tintColor {
self.tabBar.tintColor = tintColor;
}

/**
* lazy load tabItemPlaceholderImage
*
* @return UIImage
*/
- (UIImage *)tabItemPlaceholderImage {
if (_tabItemPlaceholderImage == nil) {
CGSize placeholderSize = CGSizeMake(22, 22);
UIImage *placeholderImage = [UIImage cyl_imageWithColor:[UIColor whiteColor] size:placeholderSize];
UIImage *tabItemPlaceholderImage = placeholderImage;
_tabItemPlaceholderImage = tabItemPlaceholderImage;
}
return _tabItemPlaceholderImage;
}

/**
* 添加一个子控制器
*
Expand All @@ -450,21 +468,19 @@ - (void)addOneChildViewController:(UIViewController *)viewController
lottieURL:(NSURL *)lottieURL
lottieSizeValue:(NSValue *)lottieSizeValue {
viewController.tabBarItem.title = title;
CGSize placeholderSize = CGSizeMake(22, 22);
UIImage *placeholderImage = [UIImage cyl_imageWithColor:[UIColor whiteColor] size:placeholderSize];
UIImage *normalImage = nil;
if (normalImageInfo) {
normalImage = [self getImageFromImageInfo:normalImageInfo];
} else {
normalImage = placeholderImage;
normalImage = self.tabItemPlaceholderImage;
}
viewController.tabBarItem.image = normalImage;

UIImage *selectedImage = nil;
if (selectedImageInfo) {
selectedImage = [self getImageFromImageInfo:selectedImageInfo];
} else {
selectedImage = placeholderImage;
selectedImage = self.tabItemPlaceholderImage;
}
viewController.tabBarItem.selectedImage = selectedImage;

Expand All @@ -488,6 +504,7 @@ - (void)addOneChildViewController:(UIViewController *)viewController
tureLottieSizeValue = [NSValue valueWithCGSize:normalImage.size];
break;
}
CGSize placeholderSize = CGSizeMake(22, 22);
tureLottieSizeValue = [NSValue valueWithCGSize:placeholderSize];
break;
} while (NO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ - (BOOL)cyl_isSelected {
NSUInteger tabBarSelectedIndex = self.cyl_tabBarController.selectedIndex;
NSUInteger tabBarChildViewControllerIndex = self.cyl_tabBarChildViewControllerIndex;
BOOL defaultSelected = self.selected;
if ((tabBarSelectedIndex == tabBarChildViewControllerIndex) && defaultSelected) {
if ((tabBarSelectedIndex == tabBarChildViewControllerIndex) && defaultSelected && CYLPlusChildViewController.cyl_plusViewControllerEverAdded) {
isSelected = YES;
}
return isSelected;
Expand Down
4 changes: 2 additions & 2 deletions CYLTabBarController/UIImage+CYLTabBarControllerExtention.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ + (UIImage *)cyl_assetImageName:(NSString *)assetImageName
// }
trait = [UITraitCollection traitCollectionWithUserInterfaceStyle:userInterfaceStyle];
image = [image.imageAsset imageWithTraitCollection:trait];
//TODO: 如果Xcode10加入的asset,没有加入图片,那么image是nil,还是默认是light的值?我期望是获取的light的值,要不然xcode11编译后很多图片都不会显示啊!!!!!
//TODO:
return image;
#else
#endif
Expand Down Expand Up @@ -65,7 +65,7 @@ + (UIImage *)cyl_lightOrDarkModeImageWithOwner:(id<UITraitEnvironment>)owner
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
#if __has_include(<UIKit/UIScene.h>)
//TODO: self 有自定义traitCollection,那么 [UITraitCollection currentTraitCollection]获取到的是当前系统的,还是当前self的?我期望是self的,不然的话,那就太坑了。每次都要判断self和系统两个做取舍,那太坑了!!!!!
//TODO:
UITraitCollection *traitCollection = owner.traitCollection ?: [UITraitCollection currentTraitCollection];
UIUserInterfaceStyle userInterfaceStyle = traitCollection.userInterfaceStyle;
isDarkImage = (userInterfaceStyle == UIUserInterfaceStyleDark);
Expand Down
25 changes: 18 additions & 7 deletions CYLTabBarController/UIView+CYLTabBarControllerExtention.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,24 @@ - (UIView *)cyl_tabBadgeBackgroundView {
}

- (UIImageView *)cyl_tabShadowImageView {
UIView *subview = [self cyl_tabBackgroundView];
if (!subview) {
return nil;
}
NSArray<__kindof UIView *> *backgroundSubviews = subview.subviews;
if (backgroundSubviews.count > 1) {
for (UIView *subview in backgroundSubviews) {
if (@available(iOS 10.0, *)) {
//iOS10及以上这样获取ShadowImageView:
UIView *subview = [self cyl_tabBackgroundView];
if (!subview) {
return nil;
}
NSArray<__kindof UIView *> *backgroundSubviews = subview.subviews;
//iOS13系统backgroundSubviews.count > 1可行,12及以下就不可行了
if (backgroundSubviews.count >= 1) {
for (UIView *subview in backgroundSubviews) {
if (CGRectGetHeight(subview.bounds) <= 1.0 ) {
return (UIImageView *)subview;
}
}
}
} else {
//iOS9这样获取ShadowImageView:
for (UIView *subview in self.subviews) {
if (CGRectGetHeight(subview.bounds) <= 1.0 ) {
return (UIImageView *)subview;
}
Expand Down
1 change: 1 addition & 0 deletions Example/Classes/Module/Mine/CYLMineViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self cyl_showBadgeValue:[NSString stringWithFormat:@"%@", @(indexPath.row)] animationType:CYLBadgeAnimationTypeNone];
[self testPush];
}

- (void)testPush {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":"5.1.16","fr":30,"ip":0,"op":30,"w":60,"h":60,"nm":"Tab_Discovery_Active","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Icon_Discovery_Active_Line_Circle_Small","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[30,30,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[4.418,0],[0,4.418],[-4.418,0],[0,-4.418]],"o":[[-4.418,0],[0,-4.418],[4.418,0],[0,4.418]],"v":[[0,8],[-8,0],[0,-8],[8,0]],"c":true},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.325,0.843,0.416,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":4,"ix":5},"lc":2,"lj":2,"nm":"描边 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[30,30],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"内圈","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"tm","s":{"a":0,"k":0,"ix":1},"e":{"a":1,"k":[{"i":{"x":[0.4],"y":[1]},"o":{"x":[0.6],"y":[0]},"n":["0p4_1_0p6_0"],"t":0,"s":[0],"e":[99]},{"t":20}],"ix":2},"o":{"a":0,"k":180,"ix":3},"m":1,"ix":2,"nm":"修剪路径 1","mn":"ADBE Vector Filter - Trim","hd":false}],"ip":0,"op":30,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Icon_Discovery_Active_Line_Circle_Big","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[30,30,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,-2.107],[1.432,-2.755],[3.5,-1.907],[3.46,0],[0,11.046],[-11.046,0],[-1.872,-0.58]],"o":[[0.604,1.907],[0,3.321],[-1.839,3.54],[-2.839,1.545],[-11.046,0],[0,-11.045],[2.063,0],[0,0]],"v":[[19.07,-6.044],[20,0],[17.759,9.208],[9.553,17.576],[0,20],[-20,0],[0,-20],[5.924,-19.108]],"c":false},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.325,0.843,0.416,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":4,"ix":5},"lc":2,"lj":2,"nm":"描边 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[30,30],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"外圈","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"tm","s":{"a":0,"k":0,"ix":1},"e":{"a":1,"k":[{"i":{"x":[0.875],"y":[1]},"o":{"x":[0.6],"y":[0]},"n":["0p875_1_0p6_0"],"t":20,"s":[0],"e":[100]},{"t":29}],"ix":2},"o":{"a":0,"k":0,"ix":3},"m":1,"ix":2,"nm":"修剪路径 1","mn":"ADBE Vector Filter - Trim","hd":false}],"ip":0,"op":30,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"Icon_Discovery_Active_Triangle","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.2],"y":[1]},"o":{"x":[0.167],"y":[0.048]},"n":["0p2_1_0p167_0p048"],"t":10,"s":[0],"e":[100]},{"t":14}],"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.2],"y":[1]},"o":{"x":[0.4],"y":[0]},"n":["0p2_1_0p4_0"],"t":10,"s":[-45],"e":[0]},{"t":24}],"ix":10},"p":{"a":0,"k":[30,30,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[7.779,-7.778],[0.708,7.778],[-7.779,-0.707]],"c":true},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.325,0.843,0.416,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"填充 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[37.778,22.222],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"三角","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":30,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":4,"nm":"Icon_Discovery_Active_Main","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.61],"y":[1]},"o":{"x":[0.24],"y":[0]},"n":["0p61_1_0p24_0"],"t":20,"s":[0],"e":[100]},{"t":26}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[30,30,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-3.313,0],[0,3.313],[3.313,0],[0,-3.313]],"o":[[3.313,0],[0,-3.313],[-3.313,0],[0,3.313]],"v":[[0,6],[6,0],[0,-6],[-6,0]],"c":true},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.682,0.878,0.69,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"填充 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[32,32],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"内圆","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":30,"st":0,"bm":0},{"ddd":0,"ind":5,"ty":4,"nm":"Icon_Discovery_Normal","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.8],"y":[1]},"o":{"x":[0.167],"y":[0.167]},"n":["0p8_1_0p167_0p167"],"t":0,"s":[100],"e":[6]},{"t":10}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[30,30,0],"ix":2},"a":{"a":0,"k":[30,30,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-4.418,0],[0,4.418],[4.418,0],[0,-4.418]],"o":[[4.418,0],[0,-4.418],[-4.418,0],[0,4.418]],"v":[[0,8],[8,0],[0,-8],[-8,0]],"c":true},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.498,0.498,0.498,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":4,"ix":5},"lc":2,"lj":2,"nm":"描边 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[30,30],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"组 1","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0]],"v":[[7.779,-7.778],[0.708,7.778],[-7.779,-0.707]],"c":true},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.498,0.498,0.498,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"填充 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[37.778,22.222],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"组 3","np":2,"cix":2,"ix":2,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[2.063,0],[0,-11.045],[-11.046,0],[-2.839,1.545],[-1.839,3.54],[0,3.321],[0.604,1.907]],"o":[[-1.872,-0.58],[-11.046,0],[0,11.046],[3.46,0],[3.5,-1.907],[1.432,-2.755],[0,-2.107],[0,0]],"v":[[5.924,-19.108],[0,-20],[-20,0],[0,20],[9.553,17.576],[17.759,9.208],[20,0],[19.07,-6.044]],"c":false},"ix":2},"nm":"路径 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[0.498,0.498,0.498,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":4,"ix":5},"lc":2,"lj":2,"nm":"描边 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[30,30],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"变换"}],"nm":"组 4","np":2,"cix":2,"ix":3,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":30,"st":0,"bm":0}],"markers":[]}
Loading

0 comments on commit 2eaabd6

Please sign in to comment.