jiGuangXieZuo/ProductApp/ProductApp/ProductMain/AIChart/view/AIChatBottomView.m

221 lines
8.3 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AIChatBottomView.m
// ProductApp
//
// Created by 工作 on 2024/10/14.
//
#import "AIChatBottomView.h"
#import "HuanGeSiLuCollectionViewCell.h"
#import "FSTextView.h"
@interface AIChatBottomView ()<UICollectionViewDelegate,UICollectionViewDataSource>
///
@property (nonatomic , strong) UICollectionView *collect;
///
@property (nonatomic , strong) NSArray *arrdata;
///
@property (nonatomic , strong) FSTextView *viewtext;
///
@property (nonatomic , strong) UIButton *btsend;
@property (nonatomic , strong) UIButton *btyuyin ;
@end
@implementation AIChatBottomView
-(id)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame])
{
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 0;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
UICollectionView *collect = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[collect setDelegate:self];
[collect setDataSource:self];
[collect setShowsHorizontalScrollIndicator:NO];
[collect setBackgroundColor:[UIColor clearColor]];
[self addSubview:collect];
[collect mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(0);
make.right.equalTo(self);
make.top.offset(0);
make.height.offset(40);
}];
[collect registerClass:[HuanGeSiLuCollectionViewCell class] forCellWithReuseIdentifier:@"HuanGeSiLuCollectionViewCell"];
_collect = collect;
self.arrdata = @[@"写作灵感",@"写作题材",@"语句扩写",@"作文开头",@"写作技巧",@"诗句名言"];
FSTextView *viewtext = [[FSTextView alloc] init];
[viewtext setTextColor:RGBCOLOR(51, 51, 51)];
[viewtext setTextAlignment:NSTextAlignmentLeft];
[viewtext setFont:[UIFont systemFontOfSize:14]];
[viewtext setPlaceholder:@"请输入您的想法500字以内"];
[self addSubview:viewtext];
[viewtext mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(55);
make.top.equalTo(collect.mas_bottom).offset(10);
make.right.equalTo(self).offset(-20);
make.height.offset(40);
}];
[viewtext setTextContainerInset:UIEdgeInsetsMake(10, 8, 10, 8)];
[viewtext setMaxLength:500];
[viewtext setBackgroundColor:RGBCOLOR(245, 245, 245)];
[viewtext.layer setMasksToBounds:YES];
[viewtext.layer setCornerRadius:20];
_viewtext = viewtext;
[viewtext addTextDidChangeHandler:^(FSTextView *textView) {
if(textView.text.length>0)
{
float fheight = [Tools getLabelHeightWithText:textView.text width:UISCREEN_WIDTH-55-60-16 font:14 linHeight:0]+20;
if(fheight<40)fheight=40;
if(fheight>96)fheight=96;
[self.btsend setHidden:NO];
[self.viewtext mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self).offset(-60);
make.height.offset(fheight);
}];
}
else
{
[self.btsend setHidden:YES];
[self.viewtext mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self).offset(-20);
make.height.offset(40);
}];
}
}];
UIButton *btinput = [[UIButton alloc] init];
[btinput setImage:[UIImage imageNamed:@"ai_yuyin"] forState:UIControlStateNormal];
[btinput setImage:[UIImage imageNamed:@"ai_jianpan"] forState:UIControlStateSelected];
[self addSubview:btinput];
[btinput mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.offset(40);
make.bottom.equalTo(viewtext);
make.left.offset(7);
}];
[btinput addTarget:self action:@selector(inputAction:) forControlEvents:UIControlEventTouchUpInside];
UIButton *btsend = [[UIButton alloc] init];
[btsend setImage:[UIImage imageNamed:@"ai_send"] forState:UIControlStateNormal];
[self addSubview:btsend];
[btsend mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.offset(40);
make.bottom.equalTo(viewtext);
make.right.equalTo(self).offset(-10);
}];
[btsend setHidden:YES];
[btsend addTarget:self action:@selector(sendAction) forControlEvents:UIControlEventTouchUpInside];
_btsend = btsend;
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(viewtext).offset(10);
}];
UIButton *btyuyin = [[UIButton alloc] init];
[btyuyin setTitle:@"按住说话" forState:UIControlStateNormal];
[btyuyin setTitleColor:RGBCOLOR(108, 108, 108) forState:UIControlStateNormal];
[btyuyin.titleLabel setFont:[UIFont systemFontOfSize:15]];
[btyuyin.layer setMasksToBounds:YES];
[btyuyin.layer setCornerRadius:20];
[btyuyin setBackgroundColor:RGBCOLOR(245, 245, 245)];
[self addSubview:btyuyin];
[btyuyin mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(viewtext);
make.height.offset(40);
make.right.equalTo(self).offset(-20);
}];
// [btyuyin addTarget:self action:@selector(yuyinAction) forControlEvents:UIControlEventTouchUpInside];
[btyuyin setHidden:YES];
_btyuyin = btyuyin;
}
return self;
}
-(void)inputAction:(UIButton *)sender
{
sender.selected = !sender.selected;
if(sender.selected)
{
[self.btyuyin setHidden:NO];
[self.btsend setHidden:YES];
[self.viewtext setHidden:YES];
[self endEditing:YES];
[self.viewtext mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.offset(40);
}];
}
else
{
[self.btyuyin setHidden:YES];
if(self.viewtext.text.length>0)
{
[self.btsend setHidden:NO];
}
else
{
[self.btsend setHidden:YES];
}
[self.viewtext setHidden:NO];
[self.viewtext becomeFirstResponder];
float fheight = [Tools getLabelHeightWithText:self.viewtext.text width:UISCREEN_WIDTH-55-60-16 font:14 linHeight:0]+20;
if(fheight<40)fheight=40;
if(fheight>96)fheight=96;
[self.btsend setHidden:NO];
[self.viewtext mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self).offset(-60);
make.height.offset(fheight);
}];
}
}
-(void)sendAction
{
}
#pragma mark - UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.arrdata.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
HuanGeSiLuCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HuanGeSiLuCollectionViewCell" forIndexPath:indexPath];
cell.lbname.text = self.arrdata[indexPath.row];
[cell.viewback.layer setCornerRadius:13];
return cell;
}
//定义每个section的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(7, 20, 7, 20);
}
//纵向cell间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 15;
}
//cell 间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout ForSectionAtIndex:(NSInteger)section{
return 15;
}
// 定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(72, 26);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
///做选中操作
}
@end