添加渐变色

This commit is contained in:
2026-01-16 21:37:18 +08:00
parent 552387293c
commit 063ceae10f
7 changed files with 342 additions and 152 deletions

View File

@@ -21,6 +21,10 @@
@property(nonatomic, strong) UILabel *statusLabel;
@property(nonatomic, strong) UIButton *commentButton;
@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;
@@ -34,6 +38,10 @@
- (void)viewDidLoad {
[super viewDidLoad];
//
self.edgesForExtendedLayout = UIRectEdgeAll;
self.extendedLayoutIncludesOpaqueBars = YES;
[self setupUI];
[self setupOrchestrator];
}
@@ -45,6 +53,54 @@
[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
- (void)setupUI {
@@ -54,6 +110,29 @@
//
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.text = @"按住按钮开始对话";
@@ -64,10 +143,10 @@
[self.view addSubview:self.statusLabel];
//
self.chatView = [[KBAiChatView alloc] init];
self.chatView.backgroundColor = [UIColor systemBackgroundColor];
self.chatView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.chatView];
// self.chatView = [[KBAiChatView alloc] init];
// self.chatView.backgroundColor = [UIColor systemBackgroundColor];
// self.chatView.translatesAutoresizingMaskIntoConstraints = NO;
// [self.view addSubview:self.chatView];
//
self.recordButton = [[KBAiRecordButton alloc] init];
@@ -92,51 +171,34 @@
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.commentButton];
//
[NSLayoutConstraint activateConstraints:@[
//
[self.statusLabel.topAnchor constraintEqualToAnchor:safeArea.topAnchor
constant:8],
[self.statusLabel.leadingAnchor
constraintEqualToAnchor:safeArea.leadingAnchor
constant:16],
[self.statusLabel.trailingAnchor
constraintEqualToAnchor:safeArea.trailingAnchor
constant:-16],
// - 使 Masonry
[self.tabbarBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.view);
make.height.mas_equalTo(KBFit(238));
}];
//
[self.chatView.topAnchor
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.blurEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.tabbarBackgroundView);
}];
//
[self.recordButton.leadingAnchor
constraintEqualToAnchor:safeArea.leadingAnchor
constant:20],
[self.recordButton.trailingAnchor
constraintEqualToAnchor:safeArea.trailingAnchor
constant:-20],
[self.recordButton.bottomAnchor
constraintEqualToAnchor:safeArea.bottomAnchor
constant:-16],
[self.recordButton.heightAnchor constraintEqualToConstant:50],
[self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(8);
make.left.equalTo(self.view).offset(16);
make.right.equalTo(self.view).offset(-16);
}];
//
[self.commentButton.trailingAnchor
constraintEqualToAnchor:safeArea.trailingAnchor
constant:-16],
[self.commentButton.centerYAnchor
constraintEqualToAnchor:self.chatView.centerYAnchor],
[self.commentButton.widthAnchor constraintEqualToConstant:50],
[self.commentButton.heightAnchor constraintEqualToConstant:50],
]];
[self.recordButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft).offset(20);
make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight).offset(-20);
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-16);
make.height.mas_equalTo(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
@@ -240,25 +302,25 @@
#pragma mark -
- (void)showComment {
CGFloat customViewHeight = KB_SCREEN_HEIGHT * (0.8);
KBAICommentView *customView = [[KBAICommentView alloc]
initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)];
LSTPopView *popView =
[LSTPopView initWithCustomView:customView
parentView:nil
popStyle:LSTPopStyleSmoothFromBottom
dismissStyle:LSTDismissStyleSmoothToBottom];
self.popView = popView;
popView.priority = 1000;
popView.isAvoidKeyboard = false;
popView.hemStyle = LSTHemStyleBottom;
popView.dragStyle = LSTDragStyleY_Positive;
popView.dragDistance = customViewHeight * 0.5;
popView.sweepStyle = LSTSweepStyleY_Positive;
popView.swipeVelocity = 1600;
popView.sweepDismissStyle = LSTSweepDismissStyleSmooth;
[popView pop];
CGFloat customViewHeight = KB_SCREEN_HEIGHT * (0.8);
KBAICommentView *customView = [[KBAICommentView alloc]
initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)];
LSTPopView *popView =
[LSTPopView initWithCustomView:customView
parentView:nil
popStyle:LSTPopStyleSmoothFromBottom
dismissStyle:LSTDismissStyleSmoothToBottom];
self.popView = popView;
popView.priority = 1000;
popView.isAvoidKeyboard = false;
popView.hemStyle = LSTHemStyleBottom;
popView.dragStyle = LSTDragStyleY_Positive;
popView.dragDistance = customViewHeight * 0.5;
popView.sweepStyle = LSTSweepStyleY_Positive;
popView.swipeVelocity = 1600;
popView.sweepDismissStyle = LSTSweepDismissStyleSmooth;
[popView pop];
}
- (void)showCommentDirectly {
@@ -268,12 +330,14 @@
}
CGFloat customViewHeight = KB_SCREEN_HEIGHT * (0.8);
KBAICommentView *customView = [[KBAICommentView alloc] initWithFrame:CGRectZero];
KBAICommentView *customView =
[[KBAICommentView alloc] initWithFrame:CGRectZero];
customView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:customView];
[NSLayoutConstraint activateConstraints:@[
[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.heightAnchor constraintEqualToConstant:customViewHeight],
]];