chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:35:01 +08:00
commit a2e318a963
2974 changed files with 158180 additions and 0 deletions
@@ -0,0 +1,31 @@
//
// TLEmojiBaseCell.h
// TLChat
//
// Created by 李伯坤 on 16/3/9.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLExpressionModel.h"
@protocol TLEmojiCellProtocol <NSObject>
- (CGRect)displayBaseRect;
@end
@interface TLEmojiBaseCell : UICollectionViewCell <TLEmojiCellProtocol>
@property (nonatomic, strong) TLExpressionModel *emojiItem;
@property (nonatomic, strong) UIImageView *bgView;
/**
* 选中时的背景图片,默认nil
*/
@property (nonatomic, strong) UIImage *highlightImage;
@property (nonatomic, assign) BOOL showHighlightImage;
@end
@@ -0,0 +1,50 @@
//
// TLEmojiBaseCell.m
// TLChat
//
// Created by 李伯坤 on 16/3/9.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiBaseCell.h"
@implementation TLEmojiBaseCell
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.bgView];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
}
return self;
}
- (CGRect)displayBaseRect
{
return self.frame;
}
- (void)setShowHighlightImage:(BOOL)showHighlightImage
{
if (showHighlightImage) {
[self.bgView setImage:self.highlightImage];
}
else {
[self.bgView setImage:nil];
}
}
#pragma mark - Getter -
- (UIImageView *)bgView
{
if (_bgView == nil) {
_bgView = [[UIImageView alloc] init];
[_bgView.layer setMasksToBounds:YES];
[_bgView.layer setCornerRadius:5.0f];
}
return _bgView;
}
@end
@@ -0,0 +1,13 @@
//
// TLEmojiFaceItemCell.h
// TLChat
//
// Created by 李伯坤 on 16/3/9.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiBaseCell.h"
@interface TLEmojiFaceItemCell : TLEmojiBaseCell
@end
@@ -0,0 +1,79 @@
//
// TLEmojiFaceItemCell.m
// TLChat
//
// Created by 李伯坤 on 16/3/9.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiFaceItemCell.h"
@interface TLEmojiFaceItemCell ()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *label;
@end
@implementation TLEmojiFaceItemCell
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.imageView];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(32, 32));
}];
[self.contentView addSubview:self.label];
[self.label mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.imageView);
}];
}
return self;
}
- (void)setEmojiItem:(TLExpressionModel *)emojiItem
{
[super setEmojiItem:emojiItem];
if ([emojiItem.eId isEqualToString:@"-1"]) {
[self.imageView setHidden:NO];
[self.label setHidden:YES];
[self.imageView setImage:[UIImage imageNamed:@"emojiKB_emoji_delete"]];
}
else {
if (emojiItem.type == TLEmojiTypeFace) {
[self.imageView setHidden:NO];
[self.label setHidden:YES];
[self.imageView setImage:emojiItem.name == nil ? nil : [UIImage imageNamed:emojiItem.name]];
}
else {
[self.imageView setHidden:YES];
[self.label setHidden:NO];
[self.label setText:emojiItem.name];
}
}
}
#pragma mark - # Getter
- (UIImageView *)imageView
{
if (_imageView == nil) {
_imageView = [[UIImageView alloc] init];
}
return _imageView;
}
- (UILabel *)label
{
if (_label == nil) {
_label = [[UILabel alloc] init];
[_label setFont:[UIFont systemFontOfSize:28.0f]];
[_label setTextAlignment:NSTextAlignmentCenter];
}
return _label;
}
@end
@@ -0,0 +1,14 @@
//
// TLEmojiImageItemCell.h
// TLChat
//
// Created by 李伯坤 on 16/2/20.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiBaseCell.h"
@interface TLEmojiImageItemCell : TLEmojiBaseCell
@end
@@ -0,0 +1,61 @@
//
// TLEmojiImageItemCell.m
// TLChat
//
// Created by 李伯坤 on 16/2/20.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiImageItemCell.h"
@interface TLEmojiImageItemCell ()
@property (nonatomic, strong) UIImageView *imageView;
@end
@implementation TLEmojiImageItemCell
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self.contentView addSubview:self.imageView];
[self setHighlightImage:[UIImage imageNamed:@"emoji_hl_background"]];
[self p_addMasonry];
}
return self;
}
- (CGRect)displayBaseRect
{
CGRect rect = self.imageView.frame;
rect.origin.x += self.x;
rect.origin.y += self.y;
return rect;
}
- (void)setEmojiItem:(TLExpressionModel *)emojiItem
{
[super setEmojiItem:emojiItem];
[self.imageView setImage:emojiItem.path == nil ? nil : [UIImage imageNamed:emojiItem.path]];
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(52, 52));
}];
}
#pragma mark - Getter -
- (UIImageView *)imageView
{
if (_imageView == nil) {
_imageView = [[UIImageView alloc] init];
}
return _imageView;
}
@end
@@ -0,0 +1,14 @@
//
// TLEmojiImageTitleItemCell.h
// TLChat
//
// Created by 李伯坤 on 16/2/21.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiBaseCell.h"
@interface TLEmojiImageTitleItemCell : TLEmojiBaseCell
@end
@@ -0,0 +1,86 @@
//
// TLEmojiImageTitleItemCell.m
// TLChat
//
// Created by 李伯坤 on 16/2/21.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiImageTitleItemCell.h"
#import "UIImage+Color.h"
@interface TLEmojiImageTitleItemCell ()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *label;
@end
@implementation TLEmojiImageTitleItemCell
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setHighlightImage:[UIImage imageNamed:@"emoji_hl_background"]];
[self.contentView addSubview:self.imageView];
[self.contentView addSubview:self.label];
[self p_addMasonry];
}
return self;
}
- (void)setEmojiItem:(TLExpressionModel *)emojiItem
{
[super setEmojiItem:emojiItem];
[self.imageView setImage:emojiItem.path == nil ? nil : [UIImage imageNamed:emojiItem.path]];
[self.label setText:emojiItem.name];
}
- (CGRect)displayBaseRect
{
CGRect rect = self.imageView.frame;
rect.origin.x += self.x;
rect.origin.y += self.y;
return rect;
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.imageView).mas_offset(UIEdgeInsetsMake(-3, -3, -3, -3));
}];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(3);
make.centerX.mas_equalTo(0);
make.size.mas_equalTo(CGSizeMake(50, 50));
}];
[self.label mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(0);
make.width.mas_lessThanOrEqualTo(self).mas_offset(-8);
make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(4);
}];
}
#pragma mark - Getter -
- (UIImageView *)imageView
{
if (_imageView == nil) {
_imageView = [[UIImageView alloc] init];
}
return _imageView;
}
- (UILabel *)label
{
if (_label == nil) {
_label = [[UILabel alloc] init];
[_label setFont:[UIFont systemFontOfSize:12.0f]];
[_label setTextColor:[UIColor grayColor]];
[_label setTextAlignment:NSTextAlignmentCenter];
}
return _label;
}
@end
@@ -0,0 +1,18 @@
//
// TLEmojiGroupDisplayView+CollectionView.h
// TLChat
//
// Created by 李伯坤 on 16/9/27.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiGroupDisplayView.h"
@interface TLEmojiGroupDisplayView (CollectionView) <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
- (void)registerCellClass;
- (NSUInteger)transformModelByRowCount:(NSInteger)rowCount colCount:(NSInteger)colCount andIndex:(NSInteger)index;
@end
@@ -0,0 +1,124 @@
//
// TLEmojiGroupDisplayView+CollectionView.m
// TLChat
//
// Created by 李伯坤 on 16/9/27.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiGroupDisplayView+CollectionView.h"
#import "TLEmojiFaceItemCell.h"
#import "TLEmojiImageItemCell.h"
#import "TLEmojiImageTitleItemCell.h"
@implementation TLEmojiGroupDisplayView (CollectionView)
- (void)registerCellClass
{
[self.collectionView registerClass:[TLEmojiFaceItemCell class] forCellWithReuseIdentifier:@"TLEmojiFaceItemCell"];
[self.collectionView registerClass:[TLEmojiImageItemCell class] forCellWithReuseIdentifier:@"TLEmojiImageItemCell"];
[self.collectionView registerClass:[TLEmojiImageTitleItemCell class] forCellWithReuseIdentifier:@"TLEmojiImageTitleItemCell"];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
}
- (NSUInteger)transformModelByRowCount:(NSInteger)rowCount colCount:(NSInteger)colCount andIndex:(NSInteger)index
{
NSUInteger x = index / rowCount;
NSUInteger y = index % rowCount;
return colCount * y + x;
}
#pragma mark - # Delegate
//MARK: UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return self.displayData.count;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
TLEmojiGroupDisplayModel *group = self.displayData[section];
return group.pageItemCount;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TLEmojiGroupDisplayModel *group = self.displayData[indexPath.section];
NSInteger index = [self transformModelByRowCount:group.rowNumber colCount:group.colNumber andIndex:indexPath.row];
TLExpressionModel *emoji = [group objectAtIndex:index];
TLEmojiBaseCell *cell;
if (group.type == TLEmojiTypeEmoji || group.type == TLEmojiTypeFace) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TLEmojiFaceItemCell" forIndexPath:indexPath];
}
else if (group.type == TLEmojiTypeImageWithTitle) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TLEmojiImageTitleItemCell" forIndexPath:indexPath];
}
else {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TLEmojiImageItemCell" forIndexPath:indexPath];
}
[cell setEmojiItem:emoji];
return cell;
}
//MARK: UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TLEmojiGroupDisplayModel *group = self.displayData[indexPath.section];
NSInteger index = [self transformModelByRowCount:group.rowNumber colCount:group.colNumber andIndex:indexPath.row];
TLExpressionModel *emoji = [group objectAtIndex:index];
if (emoji) {
if ([emoji.eId isEqualToString:@"-1"]) {
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiGroupDisplayViewDeleteButtonPressed:)]) {
[self.delegate emojiGroupDisplayViewDeleteButtonPressed:self];
}
}
else if (self.delegate && [self.delegate respondsToSelector:@selector(emojiGroupDisplayView:didClickedEmoji:)]) {
//FIXME: 表情类型
emoji.type = group.type;
[self.delegate emojiGroupDisplayView:self didClickedEmoji:emoji];
}
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
TLEmojiGroupDisplayModel *group = self.displayData[indexPath.section];
return group.cellSize;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
TLEmojiGroupDisplayModel *group = self.displayData[section];
return group.sectionInsets;
}
//MARK: UIScrollViewDelegate
static float lastX = 0;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSInteger page = (scrollView.contentOffset.x + 2.0) / scrollView.width;
if (scrollView.contentOffset.x < lastX) { // 右滑坐标修复
page += (scrollView.contentOffset.x - scrollView.width * page > 3.0) ? 1 : 0;
}
lastX = scrollView.contentOffset.x;
if (self.curPageIndex != page) {
self.curPageIndex = page;
if (page >= 0 && page < self.displayData.count && self.delegate && [self.delegate respondsToSelector:@selector(emojiGroupDisplayView:didScrollToPageIndex:forGroupIndex:)]) {
TLEmojiGroupDisplayModel *group = self.displayData[page];
[self.delegate emojiGroupDisplayView:self didScrollToPageIndex:group.pageIndex forGroupIndex:group.emojiGroupIndex];
}
}
}
@end
@@ -0,0 +1,15 @@
//
// TLEmojiGroupDisplayView+Gesture.h
// TLChat
//
// Created by 李伯坤 on 16/9/28.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiGroupDisplayView.h"
@interface TLEmojiGroupDisplayView (Gesture)
- (void)addGusture;
@end
@@ -0,0 +1,115 @@
//
// TLEmojiGroupDisplayView+Gesture.m
// TLChat
//
// Created by 李伯坤 on 16/9/28.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiGroupDisplayView+Gesture.h"
#import "TLEmojiGroupDisplayView+CollectionView.h"
#import "TLEmojiBaseCell.h"
@implementation TLEmojiGroupDisplayView (Gesture)
#pragma mark - # Public Methods
- (void)addGusture
{
UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
[self.collectionView addGestureRecognizer:longPressGR];
}
#pragma mark - # Event Response
static UICollectionViewCell *lastCell;
- (void)longPressAction:(UILongPressGestureRecognizer *)sender
{
TLEmojiGroupDisplayModel *curGroup = [self.displayData objectAtIndex:self.curPageIndex];
CGPoint point = [sender locationInView:self.collectionView];
if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled) { // 长按停止
[self p_cancelLongPressEmoji];
lastCell = nil;
}
else if (sender.state == UIGestureRecognizerStateBegan) {
NSArray *visableCells = self.collectionView.visibleCells;
for (TLEmojiBaseCell *cell in visableCells) {
if (cell.x <= point.x && cell.y <= point.y && cell.x + curGroup.cellSize.width >= point.x && cell.y + curGroup.cellSize.height >= point.y) {
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
NSInteger index = [self transformModelByRowCount:curGroup.rowNumber colCount:curGroup.colNumber andIndex:indexPath.row]; // 矩阵坐标转置
TLExpressionModel *emoji = [curGroup objectAtIndex:index];
if (emoji) {
if ((emoji.type == TLEmojiTypeEmoji || emoji.type == TLEmojiTypeFace) && [emoji.eId isEqualToString:@"-1"]) { // 删除
}
else {
CGRect rect = [cell displayBaseRect];
rect.origin.x = rect.origin.x - self.width * (int)(rect.origin.x / self.width);
[self p_startLongPressEmoji:emoji atRect:rect];
}
}
return;
}
}
lastCell = nil;
}
else {
NSArray *visableCells = self.collectionView.visibleCells;
for (TLEmojiBaseCell *cell in visableCells) {
if (cell.x <= point.x && cell.y <= point.y && cell.x + curGroup.cellSize.width >= point.x && cell.y + curGroup.cellSize.height >= point.y) {
if (cell == lastCell) {
return;
}
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
NSInteger index = [self transformModelByRowCount:curGroup.rowNumber colCount:curGroup.colNumber andIndex:indexPath.row]; // 矩阵坐标转置
TLExpressionModel *emoji = [curGroup objectAtIndex:index];
if (emoji) {
if ((emoji.type == TLEmojiTypeEmoji || emoji.type == TLEmojiTypeFace) && [emoji.eId isEqualToString:@"-1"]) { // 删除
[self p_cancelLongPressEmoji];
}
else {
CGRect rect = [cell displayBaseRect];
rect.origin.x = rect.origin.x - self.width * (int)(rect.origin.x / self.width);
[self p_startLongPressEmoji:emoji atRect:rect];
}
}
else { // 空白cell
[self p_cancelLongPressEmoji];
}
lastCell = cell;
return;
}
}
// 超出界限
if (lastCell) {
[self p_cancelLongPressEmoji];
lastCell = nil;
}
}
}
#pragma mark - # Private Methods
static TLExpressionModel *lastEmoji;
- (void)p_startLongPressEmoji:(TLExpressionModel *)emoji atRect:(CGRect)rect
{
if (emoji != lastEmoji) {
lastEmoji = emoji;
TLEmojiGroupDisplayModel *curGroup = [self.displayData objectAtIndex:self.curPageIndex];
emoji.type = curGroup.type;
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiGroupDisplayView:didLongPressEmoji:atRect:)]) {
[self.delegate emojiGroupDisplayView:self didLongPressEmoji:emoji atRect:rect];
}
}
}
- (void)p_cancelLongPressEmoji
{
if (lastEmoji) {
lastEmoji = nil;
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiGroupDisplayViewDidStopLongPressEmoji:)]) { // 停止长按表情
[self.delegate emojiGroupDisplayViewDidStopLongPressEmoji:self];
}
}
}
@end
@@ -0,0 +1,27 @@
//
// TLEmojiGroupDisplayView.h
// TLChat
//
// Created by 李伯坤 on 16/9/27.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TLEmojiGroupDisplayViewDelegate.h"
#import "TLEmojiGroupDisplayModel.h"
@interface TLEmojiGroupDisplayView : UIView
@property (nonatomic, weak) id<TLEmojiGroupDisplayViewDelegate> delegate;
@property (nonatomic, weak) NSMutableArray *data;
@property (nonatomic, strong) NSMutableArray *displayData;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, assign) NSInteger curPageIndex;
- (void)scrollToEmojiGroupAtIndex:(NSInteger)index;
@end
@@ -0,0 +1,125 @@
//
// TLEmojiGroupDisplayView.m
// TLChat
//
// Created by 李伯坤 on 16/9/27.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLEmojiGroupDisplayView.h"
#import "TLEmojiGroupDisplayView+CollectionView.h"
#import "TLEmojiGroupDisplayView+Gesture.h"
#import "TLExpressionGroupModel+TLEmojiKB.h"
@implementation TLEmojiGroupDisplayView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];
[self registerCellClass];
[self addGusture];
}
return self;
}
- (void)setData:(NSMutableArray *)data
{
if (data && _data && [_data isEqualToArray:data]) {
return;
}
_data = data;
self.height = HEIGHT_CHAT_KEYBOARD - 57;
self.width = SCREEN_WIDTH;
NSMutableArray *displayData = [[NSMutableArray alloc] init];
for (NSInteger emojiGroupIndex = 0; emojiGroupIndex < data.count; emojiGroupIndex++) {
TLExpressionGroupModel *group = data[emojiGroupIndex];
if (group.count > 0) { // 已下载的表情包
NSInteger cellWidth, cellHeight;
CGFloat spaceX, spaceYTop, spaceYBottom;
cellWidth = ((self.width - 20) / group.colNumber);
spaceX = (self.width - cellWidth * group.colNumber) / 2.0;
if (group.type == TLEmojiTypeEmoji || group.type == TLEmojiTypeFace) {
cellHeight = (self.height - 15) / group.rowNumber;
spaceYTop = 10;
}
else if (group.type == TLEmojiTypeImageWithTitle) {
cellHeight = (self.height - 10) / group.rowNumber;
spaceYTop = 10;
}
else {
cellHeight = (self.height - 40) / group.rowNumber;
spaceYTop = 20;
}
spaceYBottom = (self.height - cellHeight * group.rowNumber) - spaceYTop;
for (NSInteger pageIndex = 0; pageIndex < group.pageNumber; pageIndex++) {
TLEmojiGroupDisplayModel *model = [[TLEmojiGroupDisplayModel alloc] initWithEmojiGroup:group pageNumber:pageIndex andCount:group.pageItemCount];
if (model.type == TLEmojiTypeEmoji || group.type == TLEmojiTypeFace) { // 为默认表情包添加删除按钮
TLExpressionModel *emoji = [[TLExpressionModel alloc] init];
emoji.eId = @"-1";
emoji.name = @"del";
[model addEmoji:emoji];
model.pageItemCount ++;
}
model.emojiGroupIndex = emojiGroupIndex;
model.pageIndex = pageIndex;
model.cellSize = CGSizeMake(cellWidth, cellHeight);
model.sectionInsets = UIEdgeInsetsMake(spaceYTop, spaceX, spaceYBottom, spaceX);
[displayData addObject:model];
}
}
}
self.displayData = displayData;
[self.collectionView reloadData];
if (self.displayData.count > 0 && self.delegate && [self.delegate respondsToSelector:@selector(emojiGroupDisplayView:didScrollToPageIndex:forGroupIndex:)]) {
TLEmojiGroupDisplayModel *group = self.displayData[0];
[self.collectionView setContentOffset:CGPointZero];
[self.delegate emojiGroupDisplayView:self didScrollToPageIndex:0 forGroupIndex:group.emojiGroupIndex];
}
}
- (void)scrollToEmojiGroupAtIndex:(NSInteger)index
{
if (index > self.data.count) {
return;
}
_curPageIndex = index;
NSInteger page = 0;
for (int i = 0; i < index; i ++) {
TLExpressionGroupModel *group = self.data[i];
page += group.pageNumber;
}
[self.collectionView setContentOffset:CGPointMake(page * self.collectionView.width, 0)];
if (self.displayData.count > page) {
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiGroupDisplayView:didScrollToPageIndex:forGroupIndex:)]) {
TLEmojiGroupDisplayModel *group = self.displayData[page];
[self.delegate emojiGroupDisplayView:self didScrollToPageIndex:0 forGroupIndex:group.emojiGroupIndex];
}
}
}
#pragma mark - # Getter
- (UICollectionView *)collectionView
{
if (_collectionView == nil) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[_collectionView setBackgroundColor:[UIColor clearColor]];
[_collectionView setPagingEnabled:YES];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView setShowsHorizontalScrollIndicator:NO];
[_collectionView setShowsHorizontalScrollIndicator:NO];
[_collectionView setScrollsToTop:NO];
}
return _collectionView;
}
@end
@@ -0,0 +1,40 @@
//
// TLEmojiGroupDisplayViewDelegate.h
// TLChat
//
// Created by 李伯坤 on 16/9/27.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <Foundation/Foundation.h>
@class TLExpressionModel;
@class TLEmojiGroupDisplayView;
@protocol TLEmojiGroupDisplayViewDelegate <NSObject>
/**
* 发送按钮点击事件
*/
- (void)emojiGroupDisplayViewDeleteButtonPressed:(TLEmojiGroupDisplayView *)displayView;
/**
* 选中表情
*/
- (void)emojiGroupDisplayView:(TLEmojiGroupDisplayView *)displayView didClickedEmoji:(TLExpressionModel *)emoji;
/**
* 翻页
*/
- (void)emojiGroupDisplayView:(TLEmojiGroupDisplayView *)displayView didScrollToPageIndex:(NSInteger)pageIndex forGroupIndex:(NSInteger)groupIndex;
/**
* 表情长按
*/
- (void)emojiGroupDisplayView:(TLEmojiGroupDisplayView *)displayView didLongPressEmoji:(TLExpressionModel *)emoji atRect:(CGRect)rect;
/**
* 停止表情长按
*/
- (void)emojiGroupDisplayViewDidStopLongPressEmoji:(TLEmojiGroupDisplayView *)displayView;
@end