chore: import upstream snapshot with attribution
This commit is contained in:
+31
@@ -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
|
||||
+50
@@ -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
|
||||
+13
@@ -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
|
||||
+79
@@ -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
|
||||
+14
@@ -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
|
||||
+61
@@ -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
|
||||
+14
@@ -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
|
||||
+86
@@ -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
|
||||
+18
@@ -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
|
||||
+124
@@ -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
|
||||
+15
@@ -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
|
||||
+115
@@ -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
|
||||
+27
@@ -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
|
||||
+125
@@ -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
|
||||
+40
@@ -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
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// TLEmojiGroupCell.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/19.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TLExpressionGroupModel.h"
|
||||
|
||||
@interface TLEmojiGroupCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic, strong) TLExpressionGroupModel *emojiGroup;
|
||||
|
||||
@end
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// TLEmojiGroupCell.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/19.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiGroupCell.h"
|
||||
|
||||
@interface TLEmojiGroupCell ()
|
||||
|
||||
@property (nonatomic, strong) UIImageView *groupIconView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TLEmojiGroupCell
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self setBackgroundColor:[UIColor clearColor]];
|
||||
UIView *selectedView = [[UIView alloc] init];
|
||||
[selectedView setBackgroundColor:[UIColor colorGrayForChatBar]];
|
||||
[self setSelectedBackgroundView:selectedView];
|
||||
|
||||
[self.contentView addSubview:self.groupIconView];
|
||||
[self p_addMasonry];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setEmojiGroup:(TLExpressionGroupModel *)emojiGroup
|
||||
{
|
||||
_emojiGroup = emojiGroup;
|
||||
[self.groupIconView setImage:[UIImage imageNamed:emojiGroup.iconPath]];
|
||||
}
|
||||
|
||||
#pragma mark - # Private Methods
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.groupIconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.mas_equalTo(self.contentView);
|
||||
make.width.and.height.mas_lessThanOrEqualTo(30);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
[super drawRect:rect];
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSetLineWidth(context, 0.5);
|
||||
CGContextSetStrokeColorWithColor(context, [UIColor colorGrayLine].CGColor);
|
||||
CGContextBeginPath(context);
|
||||
CGContextMoveToPoint(context, self.width - 0.5, 5);
|
||||
CGContextAddLineToPoint(context, self.width - 0.5, self.height - 5);
|
||||
CGContextStrokePath(context);
|
||||
}
|
||||
|
||||
#pragma mark - Getter -
|
||||
- (UIImageView *)groupIconView
|
||||
{
|
||||
if (_groupIconView == nil) {
|
||||
_groupIconView = [[UIImageView alloc] init];
|
||||
}
|
||||
return _groupIconView;
|
||||
}
|
||||
|
||||
@end
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// TLEmojiGroupControl.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/19.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TLExpressionGroupModel.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, TLGroupControlSendButtonStatus) {
|
||||
TLGroupControlSendButtonStatusGray,
|
||||
TLGroupControlSendButtonStatusBlue,
|
||||
TLGroupControlSendButtonStatusNone,
|
||||
};
|
||||
|
||||
@class TLEmojiGroupControl;
|
||||
@protocol TLEmojiGroupControlDelegate <NSObject>
|
||||
|
||||
- (void)emojiGroupControl:(TLEmojiGroupControl*)emojiGroupControl didSelectedGroup:(TLExpressionGroupModel *)group;
|
||||
|
||||
- (void)emojiGroupControlEditButtonDown:(TLEmojiGroupControl *)emojiGroupControl;
|
||||
|
||||
- (void)emojiGroupControlEditMyEmojiButtonDown:(TLEmojiGroupControl *)emojiGroupControl;
|
||||
|
||||
- (void)emojiGroupControlSendButtonDown:(TLEmojiGroupControl *)emojiGroupControl;
|
||||
|
||||
@end
|
||||
|
||||
@interface TLEmojiGroupControl : UIView
|
||||
|
||||
@property (nonatomic, assign) TLGroupControlSendButtonStatus sendButtonStatus;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *emojiGroupData;
|
||||
|
||||
@property (nonatomic, assign) id<TLEmojiGroupControlDelegate>delegate;
|
||||
|
||||
- (void)selectEmojiGroupAtIndex:(NSInteger)index;
|
||||
|
||||
@end
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
//
|
||||
// TLEmojiGroupControl.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/19.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiGroupControl.h"
|
||||
#import "TLEmojiGroupCell.h"
|
||||
|
||||
#define WIDTH_EMOJIGROUP_CELL 46
|
||||
#define WIDTH_SENDBUTTON 60
|
||||
|
||||
@interface TLEmojiGroupControl () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
|
||||
|
||||
@property (nonatomic, strong) NSIndexPath *curIndexPath;
|
||||
|
||||
@property (nonatomic, strong) UIButton *addButton;
|
||||
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
|
||||
@property (nonatomic, strong) UIButton *sendButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TLEmojiGroupControl
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
[self setBackgroundColor:[UIColor whiteColor]];
|
||||
[self addSubview:self.addButton];
|
||||
[self addSubview:self.collectionView];
|
||||
[self addSubview:self.sendButton];
|
||||
[self p_addMasonry];
|
||||
|
||||
[self.collectionView registerClass:[TLEmojiGroupCell class] forCellWithReuseIdentifier:@"TLEmojiGroupCell"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setSendButtonStatus:(TLGroupControlSendButtonStatus)sendButtonStatus
|
||||
{
|
||||
if (_sendButtonStatus != sendButtonStatus) {
|
||||
if (_sendButtonStatus == TLGroupControlSendButtonStatusNone) {
|
||||
[self.sendButton mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self);
|
||||
}];
|
||||
[UIView animateWithDuration:0.3 animations:^{
|
||||
[self layoutIfNeeded];
|
||||
} completion:^(BOOL finished) {
|
||||
[self.collectionView reloadData];
|
||||
[self.collectionView selectItemAtIndexPath:self.curIndexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
}];
|
||||
if (sendButtonStatus == TLGroupControlSendButtonStatusBlue) {
|
||||
[_sendButton setBackgroundImage:[UIImage imageNamed:@"emojiKB_sendBtn_blue"] forState:UIControlStateNormal];
|
||||
[_sendButton setBackgroundImage:[UIImage imageNamed:@"emojiKB_sendBtn_blueHL"] forState:UIControlStateHighlighted];
|
||||
[_sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
}
|
||||
else if (sendButtonStatus == TLGroupControlSendButtonStatusGray) {
|
||||
[_sendButton setBackgroundImage:[UIImage imageNamed:@"emojiKB_sendBtn_gray"] forState:UIControlStateNormal];
|
||||
[_sendButton setBackgroundImage:[UIImage imageNamed:@"emojiKB_sendBtn_gray"] forState:UIControlStateHighlighted];
|
||||
[_sendButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
else if (sendButtonStatus == TLGroupControlSendButtonStatusNone) {
|
||||
[self.sendButton mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self).mas_offset(WIDTH_SENDBUTTON);
|
||||
}];
|
||||
[UIView animateWithDuration:0.3 animations:^{
|
||||
[self layoutIfNeeded];
|
||||
} completion:^(BOOL finished) {
|
||||
[self.collectionView reloadData];
|
||||
[self.collectionView selectItemAtIndexPath:self.curIndexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
}];
|
||||
}
|
||||
_sendButtonStatus = sendButtonStatus;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setEmojiGroupData:(NSMutableArray *)emojiGroupData
|
||||
{
|
||||
if (_emojiGroupData == emojiGroupData || [_emojiGroupData isEqualToArray:emojiGroupData]) {
|
||||
return;
|
||||
}
|
||||
_emojiGroupData = emojiGroupData;
|
||||
[self.collectionView reloadData];
|
||||
if (emojiGroupData && emojiGroupData.count > 0) {
|
||||
[self setCurIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)selectEmojiGroupAtIndex:(NSInteger)index
|
||||
{
|
||||
if (index < self.emojiGroupData.count) {
|
||||
_curIndexPath = [NSIndexPath indexPathForRow:index inSection:0];
|
||||
[self.collectionView selectItemAtIndexPath:_curIndexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
CGFloat width = WIDTH_EMOJIGROUP_CELL;
|
||||
CGFloat x = width * index;
|
||||
if (x < self.collectionView.contentOffset.x) {
|
||||
[self.collectionView setContentOffset:CGPointMake(x, 0) animated:YES];
|
||||
}
|
||||
else if (x + width > self.collectionView.contentOffset.x + self.collectionView.width) {
|
||||
[self.collectionView setContentOffset:CGPointMake(x + width - self.collectionView.width, 0) animated:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setCurIndexPath:(NSIndexPath *)curIndexPath
|
||||
{
|
||||
if (curIndexPath.row < self.emojiGroupData.count) {
|
||||
[self.collectionView scrollToItemAtIndexPath:curIndexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
|
||||
[self.collectionView selectItemAtIndexPath:curIndexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
if (_curIndexPath && _curIndexPath.section == curIndexPath.section && _curIndexPath.row == curIndexPath.row) {
|
||||
return;
|
||||
}
|
||||
|
||||
CGFloat width = WIDTH_EMOJIGROUP_CELL;
|
||||
CGFloat x = width * curIndexPath.row;
|
||||
if (x < self.collectionView.contentOffset.x) {
|
||||
[self.collectionView setContentOffset:CGPointMake(x, 0) animated:YES];
|
||||
}
|
||||
else if (x + width > self.collectionView.contentOffset.x + self.collectionView.width) {
|
||||
[self.collectionView setContentOffset:CGPointMake(x + width - self.collectionView.width, 0) animated:YES];
|
||||
}
|
||||
|
||||
_curIndexPath = curIndexPath;
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(emojiGroupControl:didSelectedGroup:)]) {
|
||||
TLExpressionGroupModel *group = [self.emojiGroupData objectAtIndex:curIndexPath.row];
|
||||
[_delegate emojiGroupControl:self didSelectedGroup:group];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - # Delegate
|
||||
//MARK: UICollectionViewDataSource
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return self.emojiGroupData.count;
|
||||
}
|
||||
|
||||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TLEmojiGroupCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TLEmojiGroupCell" forIndexPath:indexPath];
|
||||
TLExpressionGroupModel *group = [self.emojiGroupData objectAtIndex:indexPath.row];
|
||||
[cell setEmojiGroup:group];
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return CGSizeMake(WIDTH_EMOJIGROUP_CELL, self.height);
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
|
||||
{
|
||||
if (section == self.emojiGroupData.count - 1) {
|
||||
return CGSizeMake(WIDTH_EMOJIGROUP_CELL * 2, self.height);
|
||||
}
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
|
||||
//MARK: UICollectionViewDelegate
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TLExpressionGroupModel *group = [self.emojiGroupData objectAtIndex:indexPath.row];
|
||||
if (group.type == TLEmojiTypeOther) {
|
||||
//???: 存在冲突:用户选中cellA,再此方法中立马调用方法选中cellB时,所有cell都不会被选中
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self setCurIndexPath:_curIndexPath];
|
||||
});
|
||||
[self p_eidtMyEmojiButtonDown];
|
||||
}
|
||||
else {
|
||||
[self setCurIndexPath:indexPath];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - # Event Response
|
||||
- (void)emojiAddButtonDown
|
||||
{
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(emojiGroupControlEditButtonDown:)]) {
|
||||
[_delegate emojiGroupControlEditButtonDown:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sendButtonDown
|
||||
{
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(emojiGroupControlSendButtonDown:)]) {
|
||||
[_delegate emojiGroupControlSendButtonDown:self];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - # Private Methods
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.and.top.and.bottom.mas_equalTo(self);
|
||||
make.width.mas_equalTo(WIDTH_EMOJIGROUP_CELL);
|
||||
}];
|
||||
|
||||
[self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.and.bottom.and.right.mas_equalTo(self);
|
||||
make.width.mas_equalTo(WIDTH_SENDBUTTON);
|
||||
}];
|
||||
|
||||
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.and.bottom.mas_equalTo(self);
|
||||
make.left.mas_equalTo(self.addButton.mas_right);
|
||||
make.right.mas_equalTo(self.sendButton.mas_left);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)p_eidtMyEmojiButtonDown
|
||||
{
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(emojiGroupControlEditMyEmojiButtonDown:)]) {
|
||||
[_delegate emojiGroupControlEditMyEmojiButtonDown:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
[super drawRect:rect];
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSetLineWidth(context, 0.5);
|
||||
CGContextSetStrokeColorWithColor(context, [UIColor colorGrayLine].CGColor);
|
||||
CGContextBeginPath(context);
|
||||
CGContextMoveToPoint(context, WIDTH_EMOJIGROUP_CELL, 5);
|
||||
CGContextAddLineToPoint(context, WIDTH_EMOJIGROUP_CELL, self.height - 5);
|
||||
CGContextStrokePath(context);
|
||||
}
|
||||
|
||||
#pragma mark - # Getter
|
||||
- (UIButton *)addButton
|
||||
{
|
||||
if (_addButton == nil) {
|
||||
_addButton = [[UIButton alloc] init];
|
||||
[_addButton setImage:[UIImage imageNamed:@"emojiKB_groupControl_add"] forState:UIControlStateNormal];
|
||||
[_addButton addTarget:self action:@selector(emojiAddButtonDown) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _addButton;
|
||||
}
|
||||
|
||||
- (UICollectionView *)collectionView
|
||||
{
|
||||
if (_collectionView == nil) {
|
||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
|
||||
[layout setMinimumLineSpacing:0];
|
||||
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
||||
[_collectionView setBackgroundColor:[UIColor clearColor]];
|
||||
[_collectionView setDataSource:self];
|
||||
[_collectionView setDelegate:self];
|
||||
[_collectionView setShowsHorizontalScrollIndicator:NO];
|
||||
[_collectionView setShowsHorizontalScrollIndicator:NO];
|
||||
[_collectionView setScrollsToTop:NO];
|
||||
}
|
||||
return _collectionView;
|
||||
}
|
||||
|
||||
- (UIButton *)sendButton
|
||||
{
|
||||
if (_sendButton == nil) {
|
||||
_sendButton = [[UIButton alloc] init];
|
||||
[_sendButton.titleLabel setFont:[UIFont systemFontOfSize:15.0f]];
|
||||
[_sendButton setTitle:@" 发送" forState:UIControlStateNormal];
|
||||
[_sendButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
||||
[_sendButton setBackgroundColor:[UIColor clearColor]];
|
||||
[_sendButton setBackgroundImage:[UIImage imageNamed:@"emojiKB_sendBtn_gray"] forState:UIControlStateNormal];
|
||||
[_sendButton setBackgroundImage:[UIImage imageNamed:@"emojiKB_sendBtn_gray"] forState:UIControlStateHighlighted];
|
||||
[_sendButton addTarget:self action:@selector(sendButtonDown) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _sendButton;
|
||||
}
|
||||
|
||||
@end
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// TLEmojiGroupDisplayModel.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/9/27.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TLExpressionGroupModel.h"
|
||||
|
||||
@interface TLEmojiGroupDisplayModel : NSObject
|
||||
|
||||
@property (nonatomic, assign) TLEmojiType type;
|
||||
|
||||
@property (nonatomic, strong) NSString *groupID;
|
||||
|
||||
@property (nonatomic, strong) NSString *groupName;
|
||||
|
||||
@property (nonatomic, strong) NSString *groupIconPath;
|
||||
|
||||
@property (nonatomic, assign) NSUInteger count;
|
||||
|
||||
@property (nonatomic, strong) NSArray *data;
|
||||
|
||||
#pragma mark - 标记
|
||||
|
||||
@property (nonatomic, assign) NSInteger emojiGroupIndex;
|
||||
|
||||
@property (nonatomic, assign) NSInteger pageIndex;
|
||||
|
||||
#pragma mark - 展示用
|
||||
|
||||
/// 每页个数
|
||||
@property (nonatomic, assign) NSUInteger pageItemCount;
|
||||
|
||||
/// 页数
|
||||
@property (nonatomic, assign) NSUInteger pageNumber;
|
||||
|
||||
/// 行数
|
||||
@property (nonatomic, assign) NSUInteger rowNumber;
|
||||
|
||||
/// 列数
|
||||
@property (nonatomic, assign) NSUInteger colNumber;
|
||||
|
||||
@property (nonatomic, assign) CGSize cellSize;
|
||||
|
||||
@property (nonatomic, assign) UIEdgeInsets sectionInsets;
|
||||
|
||||
|
||||
- (id)initWithEmojiGroup:(TLExpressionGroupModel *)emojiGroup pageNumber:(NSInteger)pageNumber andCount:(NSInteger)count;
|
||||
|
||||
- (id)objectAtIndex:(NSUInteger)index;
|
||||
|
||||
- (void)addEmoji:(TLExpressionModel *)emoji;
|
||||
|
||||
@end
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// TLEmojiGroupDisplayModel.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/9/27.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiGroupDisplayModel.h"
|
||||
#import "TLExpressionGroupModel+TLEmojiKB.h"
|
||||
|
||||
@implementation TLEmojiGroupDisplayModel
|
||||
- (id)initWithEmojiGroup:(TLExpressionGroupModel *)emojiGroup pageNumber:(NSInteger)pageNumber andCount:(NSInteger)count
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.groupID = emojiGroup.gId;
|
||||
self.groupName = emojiGroup.name;
|
||||
self.type = emojiGroup.type;
|
||||
|
||||
self.rowNumber = emojiGroup.rowNumber;
|
||||
self.colNumber = emojiGroup.colNumber;
|
||||
self.pageItemCount = emojiGroup.pageItemCount;
|
||||
|
||||
NSInteger start = pageNumber * count;
|
||||
if (emojiGroup.data.count > start) {
|
||||
NSInteger len = MIN(count, emojiGroup.count - start);
|
||||
self.data = [emojiGroup.data subarrayWithRange:NSMakeRange(pageNumber * count, len)];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)objectAtIndex:(NSUInteger)index
|
||||
{
|
||||
return index < self.data.count ? [self.data objectAtIndex:index] : nil;
|
||||
}
|
||||
|
||||
- (void)addEmoji:(TLExpressionModel *)emoji
|
||||
{
|
||||
NSMutableArray *emojis = [NSMutableArray arrayWithArray:self.data];
|
||||
[emojis addObject:emoji];
|
||||
self.data = emojis;
|
||||
}
|
||||
@end
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// TLEmojiKeyboardDelegate.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/20.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TLExpressionModel.h"
|
||||
|
||||
@class TLEmojiKeyboard;
|
||||
@protocol TLEmojiKeyboardDelegate <NSObject>
|
||||
|
||||
- (BOOL)chatInputViewHasText;
|
||||
|
||||
@optional
|
||||
/**
|
||||
* 长按某个表情(展示)
|
||||
*/
|
||||
- (void)emojiKeyboard:(TLEmojiKeyboard *)emojiKB didTouchEmojiItem:(TLExpressionModel *)emoji atRect:(CGRect)rect;
|
||||
|
||||
/**
|
||||
* 取消长按某个表情(停止展示)
|
||||
*/
|
||||
- (void)emojiKeyboardCancelTouchEmojiItem:(TLEmojiKeyboard *)emojiKB;
|
||||
|
||||
/**
|
||||
* 点击事件 —— 选中某个表情
|
||||
*/
|
||||
- (void)emojiKeyboard:(TLEmojiKeyboard *)emojiKB didSelectedEmojiItem:(TLExpressionModel *)emoji;
|
||||
|
||||
/**
|
||||
* 点击事件 —— 表情发送按钮
|
||||
*/
|
||||
- (void)emojiKeyboardSendButtonDown;
|
||||
|
||||
/**
|
||||
* 点击事件 —— 删除按钮
|
||||
*/
|
||||
- (void)emojiKeyboardDeleteButtonDown;
|
||||
|
||||
/**
|
||||
* 点击事件 —— 表情编辑按钮
|
||||
*/
|
||||
- (void)emojiKeyboardEmojiEditButtonDown;
|
||||
|
||||
/**
|
||||
* 点击事件 —— 我的表情按钮
|
||||
*/
|
||||
- (void)emojiKeyboardMyEmojiEditButtonDown;
|
||||
|
||||
/**
|
||||
* 选中不同类型的表情组回调
|
||||
* 用于改变chatBar状态(个性表情组展示时textView不可用)
|
||||
*/
|
||||
- (void)emojiKeyboard:(TLEmojiKeyboard *)emojiKB selectedEmojiGroupType:(TLEmojiType)type;
|
||||
|
||||
@end
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// TLExpressionGroupModel+TLEmojiKB.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 2018/1/2.
|
||||
// Copyright © 2018年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLExpressionGroupModel.h"
|
||||
|
||||
@interface TLExpressionGroupModel (TLEmojiKB)
|
||||
|
||||
|
||||
/// 每页个数
|
||||
@property (nonatomic, assign, readonly) NSUInteger pageItemCount;
|
||||
|
||||
/// 页数
|
||||
@property (nonatomic, assign, readonly) NSUInteger pageNumber;
|
||||
|
||||
/// 行数
|
||||
@property (nonatomic, assign, readonly) NSUInteger rowNumber;
|
||||
|
||||
/// 列数
|
||||
@property (nonatomic, assign, readonly) NSUInteger colNumber;
|
||||
|
||||
@end
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// TLExpressionGroupModel+TLEmojiKB.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 2018/1/2.
|
||||
// Copyright © 2018年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLExpressionGroupModel+TLEmojiKB.h"
|
||||
|
||||
@implementation TLExpressionGroupModel (TLEmojiKB)
|
||||
|
||||
- (NSUInteger)rowNumber
|
||||
{
|
||||
if (self.type == TLEmojiTypeFace || self.type == TLEmojiTypeEmoji) {
|
||||
return 3;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
- (NSUInteger)colNumber
|
||||
{
|
||||
if (self.type == TLEmojiTypeFace || self.type == TLEmojiTypeEmoji) {
|
||||
return 7;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
- (NSUInteger)pageItemCount
|
||||
{
|
||||
if (self.type == TLEmojiTypeFace || self.type == TLEmojiTypeEmoji) {
|
||||
return self.rowNumber * self.colNumber - 1;
|
||||
}
|
||||
return self.rowNumber * self.colNumber;
|
||||
}
|
||||
|
||||
- (NSUInteger)pageNumber
|
||||
{
|
||||
return self.count / self.pageItemCount + (self.count % self.pageItemCount == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
@end
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// TLEmojiKeyboard+DisplayView.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/9/27.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiKeyboard.h"
|
||||
#import "TLEmojiGroupDisplayViewDelegate.h"
|
||||
|
||||
@interface TLEmojiKeyboard (DisplayView) <TLEmojiGroupDisplayViewDelegate>
|
||||
|
||||
@end
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// TLEmojiKeyboard+DisplayView.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/9/27.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiKeyboard+DisplayView.h"
|
||||
#import "TLExpressionGroupModel+TLEmojiKB.h"
|
||||
|
||||
@implementation TLEmojiKeyboard (DisplayView)
|
||||
|
||||
#pragma mark - # Delegate
|
||||
//MARK: TLEmojiGroupDisplayViewDelegate
|
||||
- (void)emojiGroupDisplayView:(TLEmojiGroupDisplayView *)displayView didClickedEmoji:(TLExpressionModel *)emoji
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboard:didSelectedEmojiItem:)]) {
|
||||
[self.delegate emojiKeyboard:self didSelectedEmojiItem:emoji];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emojiGroupDisplayViewDeleteButtonPressed:(TLEmojiGroupDisplayView *)displayView;
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboardDeleteButtonDown)]) {
|
||||
[self.delegate emojiKeyboardDeleteButtonDown];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emojiGroupDisplayView:(TLEmojiGroupDisplayView *)displayView didScrollToPageIndex:(NSInteger)pageIndex forGroupIndex:(NSInteger)groupIndex
|
||||
{
|
||||
TLExpressionGroupModel *group = self.emojiGroupData[groupIndex];
|
||||
if (self.curGroup != group) {
|
||||
self.curGroup = group;
|
||||
[self.pageControl setHidden:group.pageNumber <= 1];
|
||||
[self.pageControl setNumberOfPages:group.pageNumber];
|
||||
[self.groupControl selectEmojiGroupAtIndex:groupIndex];
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboard:selectedEmojiGroupType:)]) {
|
||||
[self.delegate emojiKeyboard:self selectedEmojiGroupType:group.type];
|
||||
}
|
||||
}
|
||||
[self.pageControl setCurrentPage:pageIndex];
|
||||
|
||||
}
|
||||
|
||||
static UICollectionViewCell *lastCell;
|
||||
- (void)emojiGroupDisplayView:(TLEmojiGroupDisplayView *)displayView didLongPressEmoji:(TLExpressionModel *)emoji atRect:(CGRect)rect
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboard:didTouchEmojiItem:atRect:)]) {
|
||||
[self.delegate emojiKeyboard:self didTouchEmojiItem:emoji atRect:rect];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emojiGroupDisplayViewDidStopLongPressEmoji:(TLEmojiGroupDisplayView *)displayView
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboardCancelTouchEmojiItem:)]) {
|
||||
[self.delegate emojiKeyboardCancelTouchEmojiItem:self];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TLEmojiKeyboard+EmojiGroupControl.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiKeyboard.h"
|
||||
|
||||
@interface TLEmojiKeyboard (EmojiGroupControl) <TLEmojiGroupControlDelegate>
|
||||
|
||||
@end
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// TLEmojiKeyboard+EmojiGroupControl.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiKeyboard+EmojiGroupControl.h"
|
||||
#import "TLExpressionGroupModel+TLEmojiKB.h"
|
||||
|
||||
@implementation TLEmojiKeyboard (EmojiGroupControl)
|
||||
|
||||
#pragma mark - Delegate
|
||||
//MARK: TLEmojiGroupControlDelegate
|
||||
- (void)emojiGroupControl:(TLEmojiGroupControl *)emojiGroupControl didSelectedGroup:(TLExpressionGroupModel *)group
|
||||
{
|
||||
// 显示Group表情
|
||||
self.curGroup = group;
|
||||
[self.displayView scrollToEmojiGroupAtIndex:[self.emojiGroupData indexOfObject:group]];
|
||||
[self.pageControl setNumberOfPages:group.pageNumber];
|
||||
[self.pageControl setCurrentPage:0];
|
||||
// 更新chatBar的textView状态
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboard:selectedEmojiGroupType:)]) {
|
||||
[self.delegate emojiKeyboard:self selectedEmojiGroupType:group.type];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emojiGroupControlEditMyEmojiButtonDown:(TLEmojiGroupControl *)emojiGroupControl
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboardMyEmojiEditButtonDown)]) {
|
||||
[self.delegate emojiKeyboardMyEmojiEditButtonDown];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emojiGroupControlEditButtonDown:(TLEmojiGroupControl *)emojiGroupControl
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboardEmojiEditButtonDown)]) {
|
||||
[self.delegate emojiKeyboardEmojiEditButtonDown];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emojiGroupControlSendButtonDown:(TLEmojiGroupControl *)emojiGroupControl
|
||||
{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(emojiKeyboardSendButtonDown)]) {
|
||||
[self.delegate emojiKeyboardSendButtonDown];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// TLEmojiKeyboard.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLBaseKeyboard.h"
|
||||
#import "TLEmojiKeyboardDelegate.h"
|
||||
#import "TLEmojiGroupControl.h"
|
||||
#import "TLEmojiGroupDisplayView.h"
|
||||
|
||||
@interface TLEmojiKeyboard : TLBaseKeyboard
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *emojiGroupData;
|
||||
|
||||
@property (nonatomic, assign) id<TLEmojiKeyboardDelegate> delegate;
|
||||
|
||||
@property (nonatomic, strong) TLExpressionGroupModel *curGroup;
|
||||
|
||||
@property (nonatomic, strong) TLEmojiGroupDisplayView *displayView;
|
||||
|
||||
@property (nonatomic, strong) UIPageControl *pageControl;
|
||||
|
||||
@property (nonatomic, strong) TLEmojiGroupControl *groupControl;
|
||||
|
||||
+ (TLEmojiKeyboard *)keyboard;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// TLEmojiKeyboard.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLEmojiKeyboard.h"
|
||||
#import "TLEmojiKeyboard+DisplayView.h"
|
||||
#import "TLEmojiKeyboard+EmojiGroupControl.h"
|
||||
#import "TLChatMacros.h"
|
||||
|
||||
static TLEmojiKeyboard *emojiKB;
|
||||
|
||||
@implementation TLEmojiKeyboard
|
||||
|
||||
+ (TLEmojiKeyboard *)keyboard
|
||||
{
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
emojiKB = [[TLEmojiKeyboard alloc] init];
|
||||
});
|
||||
return emojiKB;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
[self setBackgroundColor:[UIColor colorGrayForChatBar]];
|
||||
[self addSubview:self.displayView];
|
||||
[self addSubview:self.pageControl];
|
||||
[self addSubview:self.groupControl];
|
||||
[self p_addMasonry];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setEmojiGroupData:(NSMutableArray *)emojiGroupData
|
||||
{
|
||||
_emojiGroupData = emojiGroupData;
|
||||
[self.displayView setData:emojiGroupData];
|
||||
[self.groupControl setEmojiGroupData:emojiGroupData];
|
||||
}
|
||||
|
||||
#pragma mark - # Public Methods
|
||||
- (void)reset
|
||||
{
|
||||
// [self.collectionView scrollRectToVisible:CGRectMake(0, 0, self.collectionView.width, self.collectionView.height) animated:NO];
|
||||
}
|
||||
|
||||
#pragma mark - # Event Response
|
||||
- (void)pageControlChanged:(UIPageControl *)pageControl
|
||||
{
|
||||
// [self.collectionView scrollRectToVisible:CGRectMake(SCREEN_WIDTH * pageControl.currentPage, 0, SCREEN_WIDTH, HEIGHT_PAGECONTROL) animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - # Private Methods
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.displayView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self);
|
||||
make.left.and.right.mas_equalTo(self);
|
||||
make.bottom.mas_equalTo(self.pageControl.mas_top);
|
||||
}];
|
||||
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.and.right.mas_equalTo(self);
|
||||
make.bottom.mas_equalTo(self.groupControl.mas_top);
|
||||
make.height.mas_equalTo(20);
|
||||
}];
|
||||
[self.groupControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.and.right.and.bottom.mas_equalTo(self);
|
||||
make.height.mas_equalTo(37);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
[super drawRect:rect];
|
||||
// 顶部直线
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSetLineWidth(context, 0.5);
|
||||
CGContextSetStrokeColorWithColor(context, [UIColor colorGrayLine].CGColor);
|
||||
CGContextBeginPath(context);
|
||||
CGContextMoveToPoint(context, 0, 0);
|
||||
CGContextAddLineToPoint(context, SCREEN_WIDTH, 0);
|
||||
CGContextStrokePath(context);
|
||||
}
|
||||
|
||||
#pragma mark - # Getter
|
||||
- (TLEmojiGroupDisplayView *)displayView
|
||||
{
|
||||
if (_displayView == nil) {
|
||||
_displayView = [[TLEmojiGroupDisplayView alloc] init];
|
||||
[_displayView setDelegate:self];
|
||||
}
|
||||
return _displayView;
|
||||
}
|
||||
|
||||
- (UIPageControl *)pageControl
|
||||
{
|
||||
if (_pageControl == nil) {
|
||||
_pageControl = [[UIPageControl alloc] init];
|
||||
_pageControl.centerX = self.centerX;
|
||||
[_pageControl setPageIndicatorTintColor:[UIColor colorGrayLine]];
|
||||
[_pageControl setCurrentPageIndicatorTintColor:[UIColor grayColor]];
|
||||
[_pageControl addTarget:self action:@selector(pageControlChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
}
|
||||
return _pageControl;
|
||||
}
|
||||
|
||||
- (TLEmojiGroupControl *)groupControl
|
||||
{
|
||||
if (_groupControl == nil) {
|
||||
_groupControl = [[TLEmojiGroupControl alloc] init];
|
||||
[_groupControl setDelegate:self];
|
||||
}
|
||||
return _groupControl;
|
||||
}
|
||||
|
||||
@end
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// TLMoreKeyboardCell.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/18.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TLMoreKeyboardItem.h"
|
||||
|
||||
@interface TLMoreKeyboardCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic, strong) TLMoreKeyboardItem *item;
|
||||
|
||||
@property (nonatomic, strong) void(^clickBlock)(TLMoreKeyboardItem *item);
|
||||
|
||||
@end
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// TLMoreKeyboardCell.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/18.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLMoreKeyboardCell.h"
|
||||
#import "UIImage+Color.h"
|
||||
|
||||
@interface TLMoreKeyboardCell()
|
||||
|
||||
@property (nonatomic, strong) UIButton *iconButton;
|
||||
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TLMoreKeyboardCell
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self.contentView addSubview:self.iconButton];
|
||||
[self.contentView addSubview:self.titleLabel];
|
||||
[self p_addMasonry];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setItem:(TLMoreKeyboardItem *)item
|
||||
{
|
||||
_item = item;
|
||||
if (item == nil) {
|
||||
[self.titleLabel setHidden:YES];
|
||||
[self.iconButton setHidden:YES];
|
||||
[self setUserInteractionEnabled:NO];
|
||||
return;
|
||||
}
|
||||
[self setUserInteractionEnabled:YES];
|
||||
[self.titleLabel setHidden:NO];
|
||||
[self.iconButton setHidden:NO];
|
||||
[self.titleLabel setText:item.title];
|
||||
[self.iconButton setImage:[UIImage imageNamed:item.imagePath] forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
#pragma mark - Event Response -
|
||||
- (void)iconButtonDown:(UIButton *)sender
|
||||
{
|
||||
self.clickBlock(self.item);
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods -
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.iconButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.contentView);
|
||||
make.centerX.mas_equalTo(self.contentView);
|
||||
make.width.mas_equalTo(self.contentView);
|
||||
make.height.mas_equalTo(self.iconButton.mas_width);
|
||||
}];
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.contentView);
|
||||
make.bottom.mas_equalTo(self.contentView);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Getter -
|
||||
- (UIButton *)iconButton
|
||||
{
|
||||
if (_iconButton == nil) {
|
||||
_iconButton = [[UIButton alloc] init];
|
||||
[_iconButton.layer setMasksToBounds:YES];
|
||||
[_iconButton.layer setCornerRadius:5.0f];
|
||||
[_iconButton.layer setBorderWidth:BORDER_WIDTH_1PX];
|
||||
[_iconButton.layer setBorderColor:[UIColor grayColor].CGColor];
|
||||
[_iconButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorGrayLine]] forState:UIControlStateHighlighted];
|
||||
[_iconButton addTarget:self action:@selector(iconButtonDown:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _iconButton;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLabel
|
||||
{
|
||||
if (_titleLabel == nil) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
[_titleLabel setFont:[UIFont systemFontOfSize:12.0f]];
|
||||
[_titleLabel setTextColor:[UIColor grayColor]];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// TLMoreKeyboardDelegate.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/20.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TLMoreKeyboardItem.h"
|
||||
|
||||
@protocol TLMoreKeyboardDelegate <NSObject>
|
||||
@optional
|
||||
- (void)moreKeyboard:(id)keyboard didSelectedFunctionItem:(TLMoreKeyboardItem *)funcItem;
|
||||
|
||||
@end
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// TLMoreKeyboardItem.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/18.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef NS_ENUM(NSUInteger, TLMoreKeyboardItemType) {
|
||||
TLMoreKeyboardItemTypeImage,
|
||||
TLMoreKeyboardItemTypeCamera,
|
||||
TLMoreKeyboardItemTypeVideo,
|
||||
TLMoreKeyboardItemTypeVideoCall,
|
||||
TLMoreKeyboardItemTypeWallet,
|
||||
TLMoreKeyboardItemTypeTransfer,
|
||||
TLMoreKeyboardItemTypePosition,
|
||||
TLMoreKeyboardItemTypeFavorite,
|
||||
TLMoreKeyboardItemTypeBusinessCard,
|
||||
TLMoreKeyboardItemTypeVoice,
|
||||
TLMoreKeyboardItemTypeCards,
|
||||
};
|
||||
|
||||
@interface TLMoreKeyboardItem : NSObject
|
||||
|
||||
@property (nonatomic, assign) TLMoreKeyboardItemType type;
|
||||
|
||||
@property (nonatomic, strong) NSString *title;
|
||||
|
||||
@property (nonatomic, strong) NSString *imagePath;
|
||||
|
||||
+ (TLMoreKeyboardItem *)createByType:(TLMoreKeyboardItemType)type title:(NSString *)title imagePath:(NSString *)imagePath;
|
||||
|
||||
@end
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// TLMoreKeyboardItem.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/18.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLMoreKeyboardItem.h"
|
||||
|
||||
@implementation TLMoreKeyboardItem
|
||||
|
||||
|
||||
+ (TLMoreKeyboardItem *)createByType:(TLMoreKeyboardItemType)type title:(NSString *)title imagePath:(NSString *)imagePath
|
||||
{
|
||||
TLMoreKeyboardItem *item = [[TLMoreKeyboardItem alloc] init];
|
||||
item.type = type;
|
||||
item.title = title;
|
||||
item.imagePath = imagePath;
|
||||
return item;
|
||||
}
|
||||
|
||||
@end
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// TLMoreKeyboard+CollectionView.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLMoreKeyboard.h"
|
||||
|
||||
@interface TLMoreKeyboard (CollectionView) <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
|
||||
|
||||
@property (nonatomic, assign, readonly) NSInteger pageItemCount;
|
||||
|
||||
- (void)registerCellClass;
|
||||
|
||||
@end
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// TLMoreKeyboard+CollectionView.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLMoreKeyboard+CollectionView.h"
|
||||
#import "TLMoreKeyboardCell.h"
|
||||
|
||||
#define SPACE_TOP 15
|
||||
#define WIDTH_CELL 60
|
||||
|
||||
@implementation TLMoreKeyboard (CollectionView)
|
||||
|
||||
#pragma mark - Public Methods -
|
||||
- (void)registerCellClass
|
||||
{
|
||||
[self.collectionView registerClass:[TLMoreKeyboardCell class] forCellWithReuseIdentifier:@"TLMoreKeyboardCell"];
|
||||
}
|
||||
|
||||
#pragma mark - Delegate -
|
||||
//MARK: UICollectionViewDataSource
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||||
{
|
||||
return self.chatMoreKeyboardData.count / self.pageItemCount + (self.chatMoreKeyboardData.count % self.pageItemCount == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return self.pageItemCount;
|
||||
}
|
||||
|
||||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TLMoreKeyboardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TLMoreKeyboardCell" forIndexPath:indexPath];
|
||||
NSUInteger index = indexPath.section * self.pageItemCount + indexPath.row;
|
||||
NSUInteger tIndex = [self p_transformIndex:index]; // 矩阵坐标转置
|
||||
if (tIndex >= self.chatMoreKeyboardData.count) {
|
||||
[cell setItem:nil];
|
||||
}
|
||||
else {
|
||||
[cell setItem:self.chatMoreKeyboardData[tIndex]];
|
||||
}
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[cell setClickBlock:^(TLMoreKeyboardItem *sItem) {
|
||||
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(moreKeyboard:didSelectedFunctionItem:)]) {
|
||||
[weakSelf.delegate moreKeyboard:weakSelf didSelectedFunctionItem:sItem];
|
||||
}
|
||||
}];
|
||||
return cell;
|
||||
}
|
||||
|
||||
//MARK: UICollectionViewDelegateFlowLayout
|
||||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return CGSizeMake(WIDTH_CELL, (collectionView.height - SPACE_TOP) / 2 * 0.93);
|
||||
}
|
||||
|
||||
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
|
||||
{
|
||||
return (collectionView.width - WIDTH_CELL * self.pageItemCount / 2) / (self.pageItemCount / 2 + 1);
|
||||
}
|
||||
|
||||
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
|
||||
{
|
||||
return (collectionView.height - SPACE_TOP) / 2 * 0.07;
|
||||
}
|
||||
|
||||
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
|
||||
{
|
||||
CGFloat space = (collectionView.width - WIDTH_CELL * self.pageItemCount / 2) / (self.pageItemCount / 2 + 1);
|
||||
return UIEdgeInsetsMake(SPACE_TOP, space, 0, space);
|
||||
}
|
||||
//Mark: UIScrollViewDelegate
|
||||
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
|
||||
{
|
||||
[self.pageControl setCurrentPage:(int)(scrollView.contentOffset.x / scrollView.width)];
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods -
|
||||
- (NSUInteger)p_transformIndex:(NSUInteger)index
|
||||
{
|
||||
NSUInteger page = index / self.pageItemCount;
|
||||
index = index % self.pageItemCount;
|
||||
NSUInteger x = index / 2;
|
||||
NSUInteger y = index % 2;
|
||||
return self.pageItemCount / 2 * y + x + page * self.pageItemCount;
|
||||
}
|
||||
|
||||
#pragma mark - # Getter
|
||||
- (NSInteger)pageItemCount
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// TLMoreKeyboard.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLBaseKeyboard.h"
|
||||
#import "TLKeyboardDelegate.h"
|
||||
#import "TLMoreKeyboardDelegate.h"
|
||||
#import "TLMoreKeyboardItem.h"
|
||||
|
||||
@interface TLMoreKeyboard : TLBaseKeyboard
|
||||
|
||||
@property (nonatomic, assign) id<TLMoreKeyboardDelegate> delegate;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *chatMoreKeyboardData;
|
||||
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
|
||||
@property (nonatomic, strong) UIPageControl *pageControl;
|
||||
|
||||
+ (TLMoreKeyboard *)keyboard;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// TLMoreKeyboard.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLMoreKeyboard.h"
|
||||
#import "TLMoreKeyboard+CollectionView.h"
|
||||
#import "TLChatMacros.h"
|
||||
|
||||
static TLMoreKeyboard *moreKB;
|
||||
|
||||
@implementation TLMoreKeyboard
|
||||
|
||||
+ (TLMoreKeyboard *)keyboard
|
||||
{
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
moreKB = [[TLMoreKeyboard alloc] init];
|
||||
});
|
||||
return moreKB;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
[self setBackgroundColor:[UIColor colorGrayForChatBar]];
|
||||
[self addSubview:self.collectionView];
|
||||
[self addSubview:self.pageControl];
|
||||
[self p_addMasonry];
|
||||
|
||||
[self registerCellClass];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGFloat)keyboardHeight
|
||||
{
|
||||
return HEIGHT_CHAT_KEYBOARD;
|
||||
}
|
||||
|
||||
#pragma mark - # Public Methods
|
||||
- (void)setChatMoreKeyboardData:(NSMutableArray *)chatMoreKeyboardData
|
||||
{
|
||||
_chatMoreKeyboardData = chatMoreKeyboardData;
|
||||
[self.collectionView reloadData];
|
||||
NSUInteger pageNumber = chatMoreKeyboardData.count / self.pageItemCount + (chatMoreKeyboardData.count % self.pageItemCount == 0 ? 0 : 1);
|
||||
[self.pageControl setNumberOfPages:pageNumber];
|
||||
}
|
||||
|
||||
- (void)reset
|
||||
{
|
||||
[self.collectionView scrollRectToVisible:CGRectMake(0, 0, self.collectionView.width, self.collectionView.height) animated:NO];
|
||||
}
|
||||
|
||||
#pragma mark - # Event Response
|
||||
- (void)pageControlChanged:(UIPageControl *)pageControl
|
||||
{
|
||||
[self.collectionView scrollRectToVisible:CGRectMake(self.collectionView.width * pageControl.currentPage, 0, self.collectionView.width, self.collectionView.height) animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods -
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self);
|
||||
make.left.and.right.mas_equalTo(self);
|
||||
make.bottom.mas_equalTo(-25);
|
||||
}];
|
||||
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.and.right.mas_equalTo(self);
|
||||
make.height.mas_equalTo(20);
|
||||
make.bottom.mas_equalTo(-2);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
[super drawRect:rect];
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
CGContextSetLineWidth(context, 0.5);
|
||||
CGContextSetStrokeColorWithColor(context, [UIColor colorGrayLine].CGColor);
|
||||
CGContextBeginPath(context);
|
||||
CGContextMoveToPoint(context, 0, 0);
|
||||
CGContextAddLineToPoint(context, SCREEN_WIDTH, 0);
|
||||
CGContextStrokePath(context);
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
- (UIPageControl *)pageControl
|
||||
{
|
||||
if (_pageControl == nil) {
|
||||
_pageControl = [[UIPageControl alloc] init];
|
||||
[_pageControl setPageIndicatorTintColor:[UIColor colorGrayLine]];
|
||||
[_pageControl setCurrentPageIndicatorTintColor:[UIColor grayColor]];
|
||||
[_pageControl addTarget:self action:@selector(pageControlChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
}
|
||||
return _pageControl;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// TLBaseKeyboard.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/8/8.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TLChatMacros.h"
|
||||
#import "TLKeyboardDelegate.h"
|
||||
#import "TLKeyboardProtocol.h"
|
||||
|
||||
@interface TLBaseKeyboard : UIView <TLKeyboardProtocol>
|
||||
|
||||
/// 是否正在展示
|
||||
@property (nonatomic, assign, readonly) BOOL isShow;
|
||||
|
||||
/// 键盘事件回调
|
||||
@property (nonatomic, weak) id<TLKeyboardDelegate> keyboardDelegate;
|
||||
|
||||
/**
|
||||
* 显示键盘(在keyWindow上)
|
||||
*
|
||||
* @param animation 是否显示动画
|
||||
*/
|
||||
- (void)showWithAnimation:(BOOL)animation;
|
||||
|
||||
/**
|
||||
* 显示键盘
|
||||
*
|
||||
* @param view 父view
|
||||
* @param animation 是否显示动画
|
||||
*/
|
||||
- (void)showInView:(UIView *)view withAnimation:(BOOL)animation;
|
||||
|
||||
/**
|
||||
* 键盘消失
|
||||
*
|
||||
* @param animation 是否显示消失动画
|
||||
*/
|
||||
- (void)dismissWithAnimation:(BOOL)animation;
|
||||
|
||||
/**
|
||||
* 重置键盘
|
||||
*/
|
||||
- (void)reset;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// TLBaseKeyboard.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/8/8.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLBaseKeyboard.h"
|
||||
|
||||
@implementation TLBaseKeyboard
|
||||
|
||||
#pragma mark - # Public Methods
|
||||
- (void)showWithAnimation:(BOOL)animation
|
||||
{
|
||||
[self showInView:[UIApplication sharedApplication].keyWindow withAnimation:animation];
|
||||
}
|
||||
|
||||
- (void)showInView:(UIView *)view withAnimation:(BOOL)animation
|
||||
{
|
||||
if (_isShow) {
|
||||
return;
|
||||
}
|
||||
_isShow = YES;
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboardWillShow:animated:)]) {
|
||||
[self.keyboardDelegate chatKeyboardWillShow:self animated:animation];
|
||||
}
|
||||
[view addSubview:self];
|
||||
CGFloat keyboardHeight = [self keyboardHeight];
|
||||
[self mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.and.right.mas_equalTo(view);
|
||||
make.height.mas_equalTo(keyboardHeight);
|
||||
make.bottom.mas_equalTo(view).mas_offset(keyboardHeight);
|
||||
}];
|
||||
[view layoutIfNeeded];
|
||||
|
||||
if (animation) {
|
||||
[UIView animateWithDuration:0.3 animations:^{
|
||||
[self mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(view);
|
||||
}];
|
||||
[view layoutIfNeeded];
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboard:didChangeHeight:)]) {
|
||||
[self.keyboardDelegate chatKeyboard:self didChangeHeight:view.height - self.y];
|
||||
}
|
||||
} completion:^(BOOL finished) {
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboardDidShow:animated:)]) {
|
||||
[self.keyboardDelegate chatKeyboardDidShow:self animated:animation];
|
||||
}
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[self mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(view);
|
||||
}];
|
||||
[view layoutIfNeeded];
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboardDidShow:animated:)]) {
|
||||
[self.keyboardDelegate chatKeyboardDidShow:self animated:animation];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dismissWithAnimation:(BOOL)animation
|
||||
{
|
||||
if (!_isShow) {
|
||||
if (!animation) {
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
return;
|
||||
}
|
||||
_isShow = NO;
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboardWillDismiss:animated:)]) {
|
||||
[self.keyboardDelegate chatKeyboardWillDismiss:self animated:animation];
|
||||
}
|
||||
if (animation) {
|
||||
CGFloat keyboardHeight = [self keyboardHeight];
|
||||
[UIView animateWithDuration:0.3 animations:^{
|
||||
[self mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.superview).mas_offset(keyboardHeight);
|
||||
}];
|
||||
[self.superview layoutIfNeeded];
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboard:didChangeHeight:)]) {
|
||||
[self.keyboardDelegate chatKeyboard:self didChangeHeight:self.superview.height - self.y];
|
||||
}
|
||||
} completion:^(BOOL finished) {
|
||||
[self removeFromSuperview];
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboardDidDismiss:animated:)]) {
|
||||
[self.keyboardDelegate chatKeyboardDidDismiss:self animated:animation];
|
||||
}
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[self removeFromSuperview];
|
||||
if (self.keyboardDelegate && [self.keyboardDelegate respondsToSelector:@selector(chatKeyboardDidDismiss:animated:)]) {
|
||||
[self.keyboardDelegate chatKeyboardDidDismiss:self animated:animation];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)reset
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - # ZZKeyboardProtocol
|
||||
- (CGFloat)keyboardHeight
|
||||
{
|
||||
return HEIGHT_CHAT_KEYBOARD;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// TLKeyboardDelegate.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/2/17.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol TLKeyboardDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
@optional
|
||||
- (void)chatKeyboardWillShow:(id)keyboard animated:(BOOL)animated;
|
||||
|
||||
- (void)chatKeyboardDidShow:(id)keyboard animated:(BOOL)animated;
|
||||
|
||||
- (void)chatKeyboardWillDismiss:(id)keyboard animated:(BOOL)animated;
|
||||
|
||||
- (void)chatKeyboardDidDismiss:(id)keyboard animated:(BOOL)animated;
|
||||
|
||||
- (void)chatKeyboard:(id)keyboard didChangeHeight:(CGFloat)height;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// TLKeyboardProtocol.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/8/8.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol TLKeyboardProtocol <NSObject>
|
||||
|
||||
@required;
|
||||
- (CGFloat)keyboardHeight;
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user