添加渐变色
This commit is contained in:
22
keyBoard/Assets.xcassets/Tabbar/tabbar_alfe_icon.imageset/Contents.json
vendored
Normal file
22
keyBoard/Assets.xcassets/Tabbar/tabbar_alfe_icon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename" : "tabbar_alfe_icon@2x.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename" : "tabbar_alfe_icon@3x.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
keyBoard/Assets.xcassets/Tabbar/tabbar_alfe_icon.imageset/tabbar_alfe_icon@2x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/Tabbar/tabbar_alfe_icon.imageset/tabbar_alfe_icon@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
keyBoard/Assets.xcassets/Tabbar/tabbar_alfe_icon.imageset/tabbar_alfe_icon@3x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/Tabbar/tabbar_alfe_icon.imageset/tabbar_alfe_icon@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
21
keyBoard/Assets.xcassets/Test/person_icon.imageset/Contents.json
vendored
Normal file
21
keyBoard/Assets.xcassets/Test/person_icon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "person_icon.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
keyBoard/Assets.xcassets/Test/person_icon.imageset/person_icon.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/Test/person_icon.imageset/person_icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 315 KiB |
@@ -21,6 +21,10 @@
|
|||||||
@property(nonatomic, strong) UILabel *statusLabel;
|
@property(nonatomic, strong) UILabel *statusLabel;
|
||||||
@property(nonatomic, strong) UIButton *commentButton;
|
@property(nonatomic, strong) UIButton *commentButton;
|
||||||
@property(nonatomic, strong) KBAICommentView *commentView;
|
@property(nonatomic, strong) KBAICommentView *commentView;
|
||||||
|
@property(nonatomic, strong) UIView *tabbarBackgroundView;
|
||||||
|
@property(nonatomic, strong) UIVisualEffectView *blurEffectView;
|
||||||
|
@property(nonatomic, strong) CAGradientLayer *gradientLayer;
|
||||||
|
@property(nonatomic, strong) UIImageView *personImageView;
|
||||||
|
|
||||||
// 核心模块
|
// 核心模块
|
||||||
@property(nonatomic, strong) ConversationOrchestrator *orchestrator;
|
@property(nonatomic, strong) ConversationOrchestrator *orchestrator;
|
||||||
@@ -34,6 +38,10 @@
|
|||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
|
// 让视图延伸到屏幕边缘(包括状态栏和导航栏下方)
|
||||||
|
self.edgesForExtendedLayout = UIRectEdgeAll;
|
||||||
|
self.extendedLayoutIncludesOpaqueBars = YES;
|
||||||
|
|
||||||
[self setupUI];
|
[self setupUI];
|
||||||
[self setupOrchestrator];
|
[self setupOrchestrator];
|
||||||
}
|
}
|
||||||
@@ -45,6 +53,54 @@
|
|||||||
[self.orchestrator stop];
|
[self.orchestrator stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)viewDidLayoutSubviews {
|
||||||
|
[super viewDidLayoutSubviews];
|
||||||
|
|
||||||
|
// 设置黑色渐变层(从底部到顶部,黑色到透明)
|
||||||
|
if (!self.gradientLayer) {
|
||||||
|
self.gradientLayer = [CAGradientLayer layer];
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(0.53, 1); // 底部
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(0.54, 0); // 顶部
|
||||||
|
// 渐变颜色:从黑色 24% 不透明度到透明
|
||||||
|
self.gradientLayer.colors = @[
|
||||||
|
(__bridge id)[UIColor colorWithRed:0 / 255.0
|
||||||
|
green:0 / 255.0
|
||||||
|
blue:0 / 255.0
|
||||||
|
alpha:0.24]
|
||||||
|
.CGColor,
|
||||||
|
(__bridge id)[UIColor colorWithRed:3 / 255.0
|
||||||
|
green:3 / 255.0
|
||||||
|
blue:3 / 255.0
|
||||||
|
alpha:0]
|
||||||
|
.CGColor
|
||||||
|
];
|
||||||
|
self.gradientLayer.locations = @[ @(0.7), @(1.0) ];
|
||||||
|
[self.tabbarBackgroundView.layer addSublayer:self.gradientLayer];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新黑色渐变层的 frame
|
||||||
|
self.gradientLayer.frame = self.tabbarBackgroundView.bounds;
|
||||||
|
|
||||||
|
// 为 blurEffectView 添加透明度渐变
|
||||||
|
// mask(从底部到中间不透明,从中间到顶部透明)
|
||||||
|
if (!self.blurEffectView.layer.mask) {
|
||||||
|
CAGradientLayer *maskLayer = [CAGradientLayer layer];
|
||||||
|
maskLayer.startPoint = CGPointMake(0.5, 1); // 底部
|
||||||
|
maskLayer.endPoint = CGPointMake(0.5, 0); // 顶部
|
||||||
|
// 底部到中间保持不透明,从中间到顶部过渡透明
|
||||||
|
maskLayer.colors = @[
|
||||||
|
(__bridge id)[UIColor whiteColor].CGColor, // 底部:完全不透明
|
||||||
|
(__bridge id)[UIColor whiteColor].CGColor, // 中间:完全不透明
|
||||||
|
(__bridge id)[UIColor clearColor].CGColor // 顶部:完全透明
|
||||||
|
];
|
||||||
|
maskLayer.locations = @[ @(0.0), @(0.5), @(1.0) ];
|
||||||
|
self.blurEffectView.layer.mask = maskLayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新 mask 的 frame
|
||||||
|
self.blurEffectView.layer.mask.frame = self.blurEffectView.bounds;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - UI Setup
|
#pragma mark - UI Setup
|
||||||
|
|
||||||
- (void)setupUI {
|
- (void)setupUI {
|
||||||
@@ -54,6 +110,29 @@
|
|||||||
// 安全区域
|
// 安全区域
|
||||||
UILayoutGuide *safeArea = self.view.safeAreaLayoutGuide;
|
UILayoutGuide *safeArea = self.view.safeAreaLayoutGuide;
|
||||||
|
|
||||||
|
// PersonImageView(背景图,最底层)
|
||||||
|
self.personImageView =
|
||||||
|
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"person_icon"]];
|
||||||
|
[self.view addSubview:self.personImageView];
|
||||||
|
[self.personImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
|
make.left.right.top.bottom.equalTo(self.view);
|
||||||
|
}];
|
||||||
|
|
||||||
|
// TabBar 毛玻璃模糊背景(在 personImageView 之上)
|
||||||
|
self.tabbarBackgroundView = [[UIView alloc] init];
|
||||||
|
self.tabbarBackgroundView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
|
self.tabbarBackgroundView.clipsToBounds = YES;
|
||||||
|
[self.view addSubview:self.tabbarBackgroundView];
|
||||||
|
|
||||||
|
// 模糊效果
|
||||||
|
UIBlurEffect *blurEffect =
|
||||||
|
[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
|
||||||
|
self.blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
||||||
|
self.blurEffectView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
|
[self.tabbarBackgroundView addSubview:self.blurEffectView];
|
||||||
|
|
||||||
|
// 渐变层将在 viewDidLayoutSubviews 中设置
|
||||||
|
|
||||||
// 状态标签
|
// 状态标签
|
||||||
self.statusLabel = [[UILabel alloc] init];
|
self.statusLabel = [[UILabel alloc] init];
|
||||||
self.statusLabel.text = @"按住按钮开始对话";
|
self.statusLabel.text = @"按住按钮开始对话";
|
||||||
@@ -64,10 +143,10 @@
|
|||||||
[self.view addSubview:self.statusLabel];
|
[self.view addSubview:self.statusLabel];
|
||||||
|
|
||||||
// 聊天视图
|
// 聊天视图
|
||||||
self.chatView = [[KBAiChatView alloc] init];
|
// self.chatView = [[KBAiChatView alloc] init];
|
||||||
self.chatView.backgroundColor = [UIColor systemBackgroundColor];
|
// self.chatView.backgroundColor = [UIColor systemBackgroundColor];
|
||||||
self.chatView.translatesAutoresizingMaskIntoConstraints = NO;
|
// self.chatView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
[self.view addSubview:self.chatView];
|
// [self.view addSubview:self.chatView];
|
||||||
|
|
||||||
// 录音按钮
|
// 录音按钮
|
||||||
self.recordButton = [[KBAiRecordButton alloc] init];
|
self.recordButton = [[KBAiRecordButton alloc] init];
|
||||||
@@ -92,51 +171,34 @@
|
|||||||
forControlEvents:UIControlEventTouchUpInside];
|
forControlEvents:UIControlEventTouchUpInside];
|
||||||
[self.view addSubview:self.commentButton];
|
[self.view addSubview:self.commentButton];
|
||||||
|
|
||||||
// 布局约束
|
// 布局约束 - 使用 Masonry
|
||||||
[NSLayoutConstraint activateConstraints:@[
|
[self.tabbarBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
// 状态标签
|
make.left.right.bottom.equalTo(self.view);
|
||||||
[self.statusLabel.topAnchor constraintEqualToAnchor:safeArea.topAnchor
|
make.height.mas_equalTo(KBFit(238));
|
||||||
constant:8],
|
}];
|
||||||
[self.statusLabel.leadingAnchor
|
|
||||||
constraintEqualToAnchor:safeArea.leadingAnchor
|
|
||||||
constant:16],
|
|
||||||
[self.statusLabel.trailingAnchor
|
|
||||||
constraintEqualToAnchor:safeArea.trailingAnchor
|
|
||||||
constant:-16],
|
|
||||||
|
|
||||||
// 聊天视图
|
[self.blurEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
[self.chatView.topAnchor
|
make.edges.equalTo(self.tabbarBackgroundView);
|
||||||
constraintEqualToAnchor:self.statusLabel.bottomAnchor
|
}];
|
||||||
constant:8],
|
|
||||||
[self.chatView.leadingAnchor
|
|
||||||
constraintEqualToAnchor:safeArea.leadingAnchor],
|
|
||||||
[self.chatView.trailingAnchor
|
|
||||||
constraintEqualToAnchor:safeArea.trailingAnchor],
|
|
||||||
[self.chatView.bottomAnchor
|
|
||||||
constraintEqualToAnchor:self.recordButton.topAnchor
|
|
||||||
constant:-16],
|
|
||||||
|
|
||||||
// 录音按钮
|
[self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
[self.recordButton.leadingAnchor
|
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(8);
|
||||||
constraintEqualToAnchor:safeArea.leadingAnchor
|
make.left.equalTo(self.view).offset(16);
|
||||||
constant:20],
|
make.right.equalTo(self.view).offset(-16);
|
||||||
[self.recordButton.trailingAnchor
|
}];
|
||||||
constraintEqualToAnchor:safeArea.trailingAnchor
|
|
||||||
constant:-20],
|
|
||||||
[self.recordButton.bottomAnchor
|
|
||||||
constraintEqualToAnchor:safeArea.bottomAnchor
|
|
||||||
constant:-16],
|
|
||||||
[self.recordButton.heightAnchor constraintEqualToConstant:50],
|
|
||||||
|
|
||||||
// 评论按钮(右侧居中)
|
[self.recordButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
[self.commentButton.trailingAnchor
|
make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft).offset(20);
|
||||||
constraintEqualToAnchor:safeArea.trailingAnchor
|
make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight).offset(-20);
|
||||||
constant:-16],
|
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-16);
|
||||||
[self.commentButton.centerYAnchor
|
make.height.mas_equalTo(50);
|
||||||
constraintEqualToAnchor:self.chatView.centerYAnchor],
|
}];
|
||||||
[self.commentButton.widthAnchor constraintEqualToConstant:50],
|
|
||||||
[self.commentButton.heightAnchor constraintEqualToConstant:50],
|
[self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
]];
|
make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight).offset(-16);
|
||||||
|
make.centerY.equalTo(self.view);
|
||||||
|
make.width.height.mas_equalTo(50);
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Orchestrator Setup
|
#pragma mark - Orchestrator Setup
|
||||||
@@ -268,12 +330,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
CGFloat customViewHeight = KB_SCREEN_HEIGHT * (0.8);
|
CGFloat customViewHeight = KB_SCREEN_HEIGHT * (0.8);
|
||||||
KBAICommentView *customView = [[KBAICommentView alloc] initWithFrame:CGRectZero];
|
KBAICommentView *customView =
|
||||||
|
[[KBAICommentView alloc] initWithFrame:CGRectZero];
|
||||||
customView.translatesAutoresizingMaskIntoConstraints = NO;
|
customView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
[self.view addSubview:customView];
|
[self.view addSubview:customView];
|
||||||
[NSLayoutConstraint activateConstraints:@[
|
[NSLayoutConstraint activateConstraints:@[
|
||||||
[customView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
[customView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||||||
[customView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
[customView.trailingAnchor
|
||||||
|
constraintEqualToAnchor:self.view.trailingAnchor],
|
||||||
[customView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
|
[customView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
|
||||||
[customView.heightAnchor constraintEqualToConstant:customViewHeight],
|
[customView.heightAnchor constraintEqualToConstant:customViewHeight],
|
||||||
]];
|
]];
|
||||||
|
|||||||
@@ -7,16 +7,22 @@
|
|||||||
|
|
||||||
#import "BaseTabBarController.h"
|
#import "BaseTabBarController.h"
|
||||||
#import "HomeMainVC.h"
|
#import "HomeMainVC.h"
|
||||||
#import "MyVC.h"
|
|
||||||
#import "KBShopVC.h"
|
|
||||||
#import "KBAiMainVC.h"
|
#import "KBAiMainVC.h"
|
||||||
|
#import "KBShopVC.h"
|
||||||
|
#import "MyVC.h"
|
||||||
|
|
||||||
//#import "KBCommunityVC.h"
|
// #import "KBCommunityVC.h"
|
||||||
|
|
||||||
#import "BaseNavigationController.h"
|
#import "BaseNavigationController.h"
|
||||||
#import "KBAuthManager.h"
|
#import "KBAuthManager.h"
|
||||||
@interface BaseTabBarController ()
|
@interface BaseTabBarController ()
|
||||||
|
|
||||||
|
/// 原始的 TabBar appearance(用于恢复)
|
||||||
|
@property(nonatomic, strong)
|
||||||
|
UITabBarAppearance *originalAppearance API_AVAILABLE(ios(13.0));
|
||||||
|
@property(nonatomic, strong)
|
||||||
|
UITabBarAppearance *transparentAppearance API_AVAILABLE(ios(13.0));
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation BaseTabBarController
|
@implementation BaseTabBarController
|
||||||
@@ -33,41 +39,47 @@
|
|||||||
|
|
||||||
// 首页
|
// 首页
|
||||||
HomeMainVC *home = [[HomeMainVC alloc] init];
|
HomeMainVC *home = [[HomeMainVC alloc] init];
|
||||||
BaseNavigationController *navHome = [[BaseNavigationController alloc] initWithRootViewController:home];
|
BaseNavigationController *navHome =
|
||||||
|
[[BaseNavigationController alloc] initWithRootViewController:home];
|
||||||
navHome.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Home")
|
navHome.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Home")
|
||||||
image:@"tab_home"
|
image:@"tab_home"
|
||||||
selectedImg:@"tab_home_selected"];
|
selectedImg:@"tab_home_selected"];
|
||||||
|
|
||||||
// 商城
|
// 商城
|
||||||
KBShopVC *shop = [[KBShopVC alloc] init];
|
KBShopVC *shop = [[KBShopVC alloc] init];
|
||||||
BaseNavigationController *navShop = [[BaseNavigationController alloc] initWithRootViewController:shop];
|
BaseNavigationController *navShop =
|
||||||
|
[[BaseNavigationController alloc] initWithRootViewController:shop];
|
||||||
navShop.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Shop")
|
navShop.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Shop")
|
||||||
image:@"tab_shop"
|
image:@"tab_shop"
|
||||||
selectedImg:@"tab_shop_selected"];
|
selectedImg:@"tab_shop_selected"];
|
||||||
|
|
||||||
// AI
|
// AI
|
||||||
KBAiMainVC *aiMainVC = [[KBAiMainVC alloc] init];
|
KBAiMainVC *aiMainVC = [[KBAiMainVC alloc] init];
|
||||||
// community.title = KBLocalized(@"Circle");
|
// community.title = KBLocalized(@"Circle");
|
||||||
BaseNavigationController *navCommunity = [[BaseNavigationController alloc] initWithRootViewController:aiMainVC];
|
BaseNavigationController *navCommunity =
|
||||||
|
[[BaseNavigationController alloc] initWithRootViewController:aiMainVC];
|
||||||
navCommunity.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Circle")
|
navCommunity.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Circle")
|
||||||
image:@"tab_shequ"
|
image:@"tab_shequ"
|
||||||
selectedImg:@"tab_shequ_selected"];
|
selectedImg:@"tab_shequ_selected"];
|
||||||
|
|
||||||
// 我的
|
// 我的
|
||||||
MyVC *my = [[MyVC alloc] init];
|
MyVC *my = [[MyVC alloc] init];
|
||||||
BaseNavigationController *navMy = [[BaseNavigationController alloc] initWithRootViewController:my];
|
BaseNavigationController *navMy =
|
||||||
|
[[BaseNavigationController alloc] initWithRootViewController:my];
|
||||||
navMy.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Mine")
|
navMy.tabBarItem = [self tabItemWithTitle:KBLocalized(@"Mine")
|
||||||
image:@"tab_my"
|
image:@"tab_my"
|
||||||
selectedImg:@"tab_my_selected"];
|
selectedImg:@"tab_my_selected"];
|
||||||
|
|
||||||
self.viewControllers = @[aiMainVC,navHome, navShop, navMy];
|
self.viewControllers = @[ navHome, navShop, aiMainVC, navMy ];
|
||||||
|
|
||||||
// 测试储存Token
|
// 测试储存Token
|
||||||
// [[KBAuthManager shared] saveAccessToken:@"TEST" refreshToken:nil expiryDate:[NSDate dateWithTimeIntervalSinceNow:3600] userIdentifier:nil];
|
// [[KBAuthManager shared] saveAccessToken:@"TEST" refreshToken:nil
|
||||||
// [[KBAuthManager shared] signOut];
|
// expiryDate:[NSDate dateWithTimeIntervalSinceNow:3600]
|
||||||
|
// userIdentifier:nil];
|
||||||
|
// [[KBAuthManager shared] signOut];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupTabbarAppearance{
|
- (void)setupTabbarAppearance {
|
||||||
// 让 TabBar 不透明,子控制器 view 不再延伸到 TabBar 下
|
// 让 TabBar 不透明,子控制器 view 不再延伸到 TabBar 下
|
||||||
self.tabBar.translucent = NO;
|
self.tabBar.translucent = NO;
|
||||||
if (@available(iOS 15.0, *)) {
|
if (@available(iOS 15.0, *)) {
|
||||||
@@ -75,47 +87,85 @@
|
|||||||
[a configureWithOpaqueBackground];
|
[a configureWithOpaqueBackground];
|
||||||
a.backgroundColor = [UIColor whiteColor];
|
a.backgroundColor = [UIColor whiteColor];
|
||||||
// 设置选中标题为黑色(iOS 15+ 需通过 appearance)
|
// 设置选中标题为黑色(iOS 15+ 需通过 appearance)
|
||||||
NSDictionary *selAttr = @{ NSForegroundColorAttributeName : [UIColor blackColor] };
|
NSDictionary *selAttr =
|
||||||
|
@{NSForegroundColorAttributeName : [UIColor blackColor]};
|
||||||
a.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
|
a.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
a.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
a.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
a.compactInlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
a.compactInlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
self.tabBar.standardAppearance = a;
|
self.tabBar.standardAppearance = a;
|
||||||
self.tabBar.scrollEdgeAppearance = a;
|
self.tabBar.scrollEdgeAppearance = a;
|
||||||
|
|
||||||
|
// 保存原始 appearance
|
||||||
|
self.originalAppearance = a;
|
||||||
|
|
||||||
|
// 创建透明 appearance
|
||||||
|
UITabBarAppearance *transparentA = [UITabBarAppearance new];
|
||||||
|
[transparentA configureWithTransparentBackground];
|
||||||
|
transparentA.backgroundColor = [UIColor clearColor];
|
||||||
|
transparentA.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
|
transparentA.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
|
transparentA.compactInlineLayoutAppearance.selected.titleTextAttributes =
|
||||||
|
selAttr;
|
||||||
|
self.transparentAppearance = transparentA;
|
||||||
} else if (@available(iOS 13.0, *)) {
|
} else if (@available(iOS 13.0, *)) {
|
||||||
UITabBarAppearance *a = [UITabBarAppearance new];
|
UITabBarAppearance *a = [UITabBarAppearance new];
|
||||||
[a configureWithOpaqueBackground];
|
[a configureWithOpaqueBackground];
|
||||||
a.backgroundColor = [UIColor whiteColor];
|
a.backgroundColor = [UIColor whiteColor];
|
||||||
NSDictionary *selAttr = @{ NSForegroundColorAttributeName : [UIColor blackColor] };
|
NSDictionary *selAttr =
|
||||||
|
@{NSForegroundColorAttributeName : [UIColor blackColor]};
|
||||||
a.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
|
a.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
a.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
a.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
a.compactInlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
a.compactInlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
self.tabBar.standardAppearance = a;
|
self.tabBar.standardAppearance = a;
|
||||||
self.tabBar.tintColor = [UIColor blackColor];
|
self.tabBar.tintColor = [UIColor blackColor];
|
||||||
|
|
||||||
|
// 保存原始 appearance
|
||||||
|
self.originalAppearance = a;
|
||||||
|
|
||||||
|
// 创建透明 appearance
|
||||||
|
UITabBarAppearance *transparentA = [UITabBarAppearance new];
|
||||||
|
[transparentA configureWithTransparentBackground];
|
||||||
|
transparentA.backgroundColor = [UIColor clearColor];
|
||||||
|
transparentA.stackedLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
|
transparentA.inlineLayoutAppearance.selected.titleTextAttributes = selAttr;
|
||||||
|
transparentA.compactInlineLayoutAppearance.selected.titleTextAttributes =
|
||||||
|
selAttr;
|
||||||
|
self.transparentAppearance = transparentA;
|
||||||
} else {
|
} else {
|
||||||
// 老系统用 tintColor/appearance 做回退
|
// 老系统用 tintColor/appearance 做回退
|
||||||
self.tabBar.tintColor = [UIColor blackColor];
|
self.tabBar.tintColor = [UIColor blackColor];
|
||||||
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}
|
[[UITabBarItem appearance] setTitleTextAttributes:@{
|
||||||
|
NSForegroundColorAttributeName : [UIColor blackColor]
|
||||||
|
}
|
||||||
forState:UIControlStateSelected];
|
forState:UIControlStateSelected];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统一构造 TabBarItem,原图渲染,避免被系统 Tint 着色
|
// 统一构造 TabBarItem,原图渲染,避免被系统 Tint 着色
|
||||||
- (UITabBarItem *)tabItemWithTitle:(NSString *)title image:(NSString *)imageName selectedImg:(NSString *)selectedName {
|
- (UITabBarItem *)tabItemWithTitle:(NSString *)title
|
||||||
UIImage *img = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
image:(NSString *)imageName
|
||||||
UIImage *sel = [[UIImage imageNamed:selectedName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
selectedImg:(NSString *)selectedName {
|
||||||
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title image:img selectedImage:sel];
|
UIImage *img = [[UIImage imageNamed:imageName]
|
||||||
|
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||||||
|
UIImage *sel = [[UIImage imageNamed:selectedName]
|
||||||
|
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||||||
|
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title
|
||||||
|
image:img
|
||||||
|
selectedImage:sel];
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - UITabBarControllerDelegate
|
#pragma mark - UITabBarControllerDelegate
|
||||||
|
|
||||||
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
|
- (BOOL)tabBarController:(UITabBarController *)tabBarController
|
||||||
|
shouldSelectViewController:(UIViewController *)viewController {
|
||||||
// 已经是当前选中的 tab,直接允许(避免重复拦截)
|
// 已经是当前选中的 tab,直接允许(避免重复拦截)
|
||||||
if (tabBarController.selectedViewController == viewController) {
|
if (tabBarController.selectedViewController == viewController) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSUInteger index = [tabBarController.viewControllers indexOfObject:viewController];
|
NSUInteger index =
|
||||||
|
[tabBarController.viewControllers indexOfObject:viewController];
|
||||||
if (index == NSNotFound) {
|
if (index == NSNotFound) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@@ -129,10 +179,43 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)tabBarController:(UITabBarController *)tabBarController
|
||||||
|
didSelectViewController:(UIViewController *)viewController {
|
||||||
|
NSUInteger index =
|
||||||
|
[tabBarController.viewControllers indexOfObject:viewController];
|
||||||
|
|
||||||
|
// 第三个 tab(索引2)是 KBAiMainVC,背景透明
|
||||||
|
if (index == 2) {
|
||||||
|
if (@available(iOS 13.0, *)) {
|
||||||
|
self.tabBar.standardAppearance = self.transparentAppearance;
|
||||||
|
if (@available(iOS 15.0, *)) {
|
||||||
|
self.tabBar.scrollEdgeAppearance = self.transparentAppearance;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// iOS 13 以下,直接设置背景色
|
||||||
|
self.tabBar.barTintColor = [UIColor clearColor];
|
||||||
|
self.tabBar.backgroundColor = [UIColor clearColor];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他 tab,恢复原始背景
|
||||||
|
if (@available(iOS 13.0, *)) {
|
||||||
|
self.tabBar.standardAppearance = self.originalAppearance;
|
||||||
|
if (@available(iOS 15.0, *)) {
|
||||||
|
self.tabBar.scrollEdgeAppearance = self.originalAppearance;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// iOS 13 以下,恢复白色背景
|
||||||
|
self.tabBar.barTintColor = [UIColor whiteColor];
|
||||||
|
self.tabBar.backgroundColor = [UIColor whiteColor];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#pragma mark - Navigation
|
#pragma mark - Navigation
|
||||||
|
|
||||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
// In a storyboard-based application, you will often want to do a little
|
||||||
|
preparation before navigation
|
||||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||||||
// Get the new view controller using [segue destinationViewController].
|
// Get the new view controller using [segue destinationViewController].
|
||||||
// Pass the selected object to the new view controller.
|
// Pass the selected object to the new view controller.
|
||||||
|
|||||||
Reference in New Issue
Block a user