123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- //
- // SmartBar.m
- // smartRhino
- //
- // Created by niuzhen on 2019/12/14.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "SmartBar.h"
- #import "GHRefreshCollectionView.h"
- #import "NoticeNewGroupMenuCell.h"
- #import "ZLCollectionViewFlowLayout.h"
- #import "TDButton.h"
- #define BARHEIGHT 42.5f
- @interface SmartBar()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic, copy) NSMutableArray <SmartBarModel>* listArray;
- @property (nonatomic, assign)CGFloat SmartHeight;
- @property (strong,nonatomic) UICollectionView *collectionView;
- @property (nonatomic,strong) UIView *chatBar;
- @property (nonatomic,strong) TDButton *addBtn;
- @property (nonatomic,strong) TDButton *keyBtn;
- @property (nonatomic,assign) BOOL keyBoardIsShow;
- @end
- @implementation SmartBar
- - (instancetype)initHeight:(CGFloat)height AddBarArray:(NSMutableArray<SmartBarModel> *)array;
- {
- self = [super init];
- if (self) {
- self.listArray = array;
- self.SmartHeight = height;
- [self addBarSubView];
- }
- return self;
- }
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.SmartHeight = BARHEIGHT;
- [self addBarSubView];
- }
- return self;
- }
- - (void)addBarSubView
- {
- [self addSubview:self.chatBar];
- [self.chatBar addSubview:self.addBtn];
- [self.chatBar addSubview:self.keyBtn];
- [self.chatBar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.mas_equalTo(self);
- make.height.mas_offset(self.SmartHeight);
- }];
- UILabel * topLineL = [UILabel new];
- topLineL.backgroundColor = UIColorHex(B4B4B4);
- UILabel * botLineL = [UILabel new];
- botLineL.backgroundColor = UIColorHex(B4B4B4);
- UILabel * hLineL = [UILabel new];
- hLineL.backgroundColor = UIColorHex(B4B4B4);
- [self.chatBar addSubview:topLineL];
- [self.chatBar addSubview:botLineL];
- [self.chatBar addSubview:hLineL];
- [topLineL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.mas_equalTo(self.chatBar);
- make.height.mas_offset(0.5);
- }];
- [botLineL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.mas_equalTo(self.chatBar);
- make.height.mas_offset(0.5);
- }];
- [hLineL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.mas_equalTo(self.chatBar);
- make.width.mas_offset(0.5);
- make.right.mas_equalTo(self.chatBar.mas_right).offset(-50);
- }];
- [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(10);
- make.left.mas_offset(22);
- make.size.mas_offset(CGSizeMake(22, 22));
- }];
- [self.keyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(10.5);
- make.right.mas_offset(-13.5);
- make.size.mas_offset(CGSizeMake(23.5, 21.5));
- }];
-
- [self CreatelistView];
- WS(weakSelf);
- [self.addBtn setAction:^{
- // if (weakSelf.collectionView.isHidden) {
- // weakSelf.collectionView.hidden = NO;
- // }else{
- // weakSelf.collectionView.hidden = YES;
- // }
- weakSelf.collectionView.hidden = NO;
- if(weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didSelectBarAddBtnIsShow:)]){
- [weakSelf.delegate didSelectBarAddBtnIsShow:YES];
- }
- [weakSelf mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_offset(weakSelf.SmartHeight * 2 + (weakSelf.collectionView.isHidden ? 0 : Height_SCALE(215)));
- }];
- }];
- [self.keyBtn setAction:^{
- [weakSelf downBar];
- if(weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didSelectBarKeyBtnIsShow:)]){
- [weakSelf.delegate didSelectBarKeyBtnIsShow:!weakSelf.keyBoardIsShow];
- }
- }];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- }
- - (void)CreatelistView
- {
- [self addSubview:self.collectionView];
- self.collectionView.hidden = YES;
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.mas_equalTo(self);
- make.top.mas_equalTo(self.chatBar.mas_bottom);
- }];
- if (self.listArray.count == 0) {
- NSArray * array = @[@{@"name":@"图片",@"image":@"chatmsg_notice_photo_icon",@"type":@(0)},
- @{@"name":@"拍摄",@"image":@"chatmsg_notice_xiangji_icon",@"type":@(1)},
- @{@"name":@"我的笔记",@"image":@"chatmsg_notice_biji_icon",@"type":@(2)},
- @{@"name":@"我的收藏",@"image":@"chatmsg_notice_sc_icon",@"type":@(3)},
- @{@"name":@"文件",@"image":@"chatmsg_notice_file_icon",@"type":@(4)}];
- for (NSDictionary * dict in array) {
- SmartBarModel * model = [[SmartBarModel alloc] init];
- model.name = [dict objectForKey:@"name"];
- model.image = [dict objectForKey:@"image"];
- model.type = [[dict objectForKey:@"type"] intValue];
- [self.listArray addObject:model];
- }
- }
- [self.collectionView reloadData];
- }
- - (void)downBar
- {
- if (!self.collectionView.hidden) {
- self.collectionView.hidden = YES;
- }
- [self.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_offset(self.SmartHeight);
- }];
- [self mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_offset(self.SmartHeight);
- }];
- }
- #pragma mark - UICollectionView
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.listArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- SmartBarModel * model = [self.listArray objectAtIndex:indexPath.item];
- NoticeNewGroupMenuCell *cell = [ collectionView dequeueReusableCellWithReuseIdentifier:@"NoticeNewGroupMenuCell" forIndexPath:indexPath];
- cell.cell0ImgView.image = [UIImage imageNamed:model.image];
- cell.cell0TitleLabel.text = model.name;
- return cell;
- }
- /****************************************************/
- #pragma mark --UICollectionViewDelegateFlowLayout
- /****************************************************/
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- CGFloat width = (SCREEN_WIDTH - 60 - 75) * 0.25;
- CGFloat height = Height_SCALE(100);
- return CGSizeMake(width, height);
- }
- //设置每个item的UIEdgeInsets
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- return UIEdgeInsetsMake(0, 0, 0, 0);
- }
- //设置每个item水平间距
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
- {
- return 25.f;
- }
- //设置每个item垂直间距
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
- {
- return 0.f;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
- SmartBarModel * model = [self.listArray objectAtIndex:indexPath.item];
- if(self.delegate && [self.delegate respondsToSelector:@selector(didSelectBarWithType:)]){
- [self.delegate didSelectBarWithType:model.type];
- }
- }
- #pragma mark - CusView
- - (UICollectionView *)collectionView
- {
- if (!_collectionView) {
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
- [_collectionView registerNib:[UINib nibWithNibName:@"NoticeNewGroupMenuCell" bundle:nil] forCellWithReuseIdentifier:@"NoticeNewGroupMenuCell"];
- _collectionView.backgroundColor = UIColorHex(#F4F4F6);
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.showsHorizontalScrollIndicator = NO;
- _collectionView.contentInset = UIEdgeInsetsMake(0, 30, 0, 30);
- _collectionView.alwaysBounceVertical = YES;
- _collectionView.scrollEnabled = NO;
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- }
- return _collectionView;
- }
- - (UIView *)chatBar
- {
- if (!_chatBar) {
- _chatBar = [UIView new];
- _chatBar.backgroundColor = UIColorHex(FAFAFA);
- }
- return _chatBar;
- }
- - (TDButton *)addBtn
- {
- if (!_addBtn) {
- _addBtn = [TDButton new];
- [_addBtn setImage:[UIImage imageNamed:@"smart_add"] forState:UIControlStateNormal];
- [_addBtn setCurrentButtonHotSize:CGSizeMake(BARHEIGHT, BARHEIGHT)];
- }
- return _addBtn;
- }
- - (TDButton *)keyBtn
- {
- if (!_keyBtn) {
- _keyBtn = [TDButton new];
- [_keyBtn setImage:[UIImage imageNamed:@"smart_key"] forState:UIControlStateNormal];
- [_keyBtn setCurrentButtonHotSize:CGSizeMake(BARHEIGHT, BARHEIGHT)];
- }
- return _keyBtn;
- }
- - (NSMutableArray *)listArray
- {
- if (!_listArray) {
- _listArray = [NSMutableArray array];
- }
- return _listArray;
- }
- #pragma mark - KeyBoard
- - (void)keyBoardWillShow:(NSNotification *)note
- {
- [self downBar];
- self.keyBoardIsShow = YES;
- }
- - (void)keyBoardWillHide:(NSNotification *)note
- {
- self.keyBoardIsShow = NO;
- }
- - (void)dealloc{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|