From 3e8437ae559487362fae3525beb79c534c213a51 Mon Sep 17 00:00:00 2001 From: 单军华 Date: Thu, 12 Jul 2018 13:44:34 +0800 Subject: [PATCH] bug修复和功能优化 --- screendisplay/Pods/HMEmoticon/表情键盘/Emoticon/HMEmoticonCell.m | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 169 insertions(+), 0 deletions(-) diff --git "a/screendisplay/Pods/HMEmoticon/\350\241\250\346\203\205\351\224\256\347\233\230/Emoticon/HMEmoticonCell.m" "b/screendisplay/Pods/HMEmoticon/\350\241\250\346\203\205\351\224\256\347\233\230/Emoticon/HMEmoticonCell.m" new file mode 100755 index 0000000..d3c8dc7 --- /dev/null +++ "b/screendisplay/Pods/HMEmoticon/\350\241\250\346\203\205\351\224\256\347\233\230/Emoticon/HMEmoticonCell.m" @@ -0,0 +1,169 @@ +// +// HMEmoticonCell.m +// ������������ +// +// Created by ������ on 16/3/3. +// Copyright �� 2016��� itcast. All rights reserved. +// + +#import "HMEmoticonCell.h" +#import "HMEmoticon.h" +#import "UIImage+HMEmoticon.h" +#import "HMEmoticonTipView.h" +#import "HMEmoticonButton.h" + +@implementation HMEmoticonCell { + HMEmoticonTipView *_tipView; + UILabel *_recentLabel; + HMEmoticonButton *_deleteButton; +} + +#pragma mark - ������������ +- (void)setEmoticons:(NSArray<HMEmoticon *> *)emoticons { + _emoticons = emoticons; + + for (UIView *v in self.contentView.subviews) { + v.hidden = YES; + } + _deleteButton.hidden = NO; + + NSInteger index = 0; + for (HMEmoticon *e in _emoticons) { + HMEmoticonButton *btn = self.contentView.subviews[index++]; + + btn.emoticon = e; + } +} + +- (void)setIndexPath:(NSIndexPath *)indexPath { + _indexPath = indexPath; + _recentLabel.hidden = indexPath.section != 0; +} + +#pragma mark - ������������ +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + [self prepareUI]; + + // ������������������ + UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] + initWithTarget:self + action:@selector(longPressed:)]; + + longPressGesture.minimumPressDuration = 0.1; + + [self addGestureRecognizer:longPressGesture]; + } + return self; +} + +- (void)didMoveToWindow { + [super didMoveToWindow]; + + [self.window addSubview:_tipView]; + _tipView.hidden = YES; +} + +#pragma mark - ������������ +- (void)longPressed:(UILongPressGestureRecognizer *)recognizer { + + CGPoint location = [recognizer locationInView:self]; + + // ������������������ + HMEmoticonButton *button = nil; + for (HMEmoticonButton *btn in self.contentView.subviews) { + if (CGRectContainsPoint(btn.frame, location) && !btn.hidden) { + button = btn; + break; + } + } + if (button == nil) { + _tipView.hidden = YES; + + return; + } + + switch (recognizer.state) { + case UIGestureRecognizerStateBegan: + case UIGestureRecognizerStateChanged: { + CGPoint buttonCenter = [self.contentView convertPoint:button.center toView:self.window]; + + _tipView.center = buttonCenter; + _tipView.emoticon = button.emoticon; + + _tipView.hidden = (button == _deleteButton); + } + break; + case UIGestureRecognizerStateEnded: + [self clickEmoticonButton:button]; + case UIGestureRecognizerStateCancelled: + case UIGestureRecognizerStateFailed: + _tipView.hidden = YES; + break; + default: + break; + } +} + +- (void)clickEmoticonButton:(HMEmoticonButton *)button { + [self.delegate emoticonCellDidSelectedEmoticon:button.emoticon isRemoved:button.isDeleteButton]; +} + +#pragma mark - ������������ +- (void)prepareUI { + NSInteger rowCount = 3; + NSInteger colCount = 7; + + CGFloat leftMargin = 8; + CGFloat bottomMargin = 20; + + CGFloat w = ceil((self.bounds.size.width - 2 * leftMargin) / colCount); + CGFloat h = ceil((self.bounds.size.height - bottomMargin) / rowCount); + + for (NSInteger i = 0; i < 21; i++) { + NSInteger col = i % colCount; + NSInteger row = i / colCount; + + CGRect rect = CGRectMake(col * w + leftMargin, row * h, w, h); + UIButton *button = [HMEmoticonButton emoticonButtonWithFrame:rect tag:i]; + + [self.contentView addSubview:button]; + + [button addTarget:self + action:@selector(clickEmoticonButton:) + forControlEvents:UIControlEventTouchUpInside]; + } + + // ������������ + _deleteButton = ((HMEmoticonButton *)self.contentView.subviews.lastObject); + _deleteButton.deleteButton = YES; + + // ������������ + _tipView = [[HMEmoticonTipView alloc] init]; + + _recentLabel = [[UILabel alloc] init]; + _recentLabel.text = @"���������������������"; + _recentLabel.textColor = [UIColor lightGrayColor]; + _recentLabel.font = [UIFont systemFontOfSize:12]; + [self.contentView addSubview:_recentLabel]; + + _recentLabel.translatesAutoresizingMaskIntoConstraints = false; + [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_recentLabel + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeCenterX + multiplier:1 + constant:0]]; + + [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_recentLabel + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationEqual + toItem:self.contentView + attribute:NSLayoutAttributeBottom + multiplier:1 + constant:-5]]; +} + +@end -- Gitblit v1.8.0