mirror of
https://github.com/TencentCloud/TIMSDK.git
synced 2026-10-22 01:06:31 +08:00
125 lines
3.7 KiB
Objective-C
125 lines
3.7 KiB
Objective-C
//
|
|
// TUIImageMessageCell.m
|
|
// UIKit
|
|
//
|
|
// Created by annidyfeng on 2019/5/30.
|
|
//
|
|
|
|
#import "TUIImageMessageCell.h"
|
|
#import "TUIDefine.h"
|
|
|
|
@interface TUIImageMessageCell ()
|
|
|
|
@property (nonatomic, strong) UIView *animateHighlightView;
|
|
|
|
@end
|
|
|
|
@implementation TUIImageMessageCell
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
{
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|
if (self) {
|
|
_thumb = [[UIImageView alloc] init];
|
|
_thumb.layer.cornerRadius = 5.0;
|
|
[_thumb.layer setMasksToBounds:YES];
|
|
_thumb.contentMode = UIViewContentModeScaleAspectFit;
|
|
_thumb.backgroundColor = [UIColor whiteColor];
|
|
[self.container addSubview:_thumb];
|
|
_thumb.mm_fill();
|
|
_thumb.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
|
|
_progress = [[UILabel alloc] init];
|
|
_progress.textColor = [UIColor whiteColor];
|
|
_progress.font = [UIFont systemFontOfSize:15];
|
|
_progress.textAlignment = NSTextAlignmentCenter;
|
|
_progress.layer.cornerRadius = 5.0;
|
|
_progress.hidden = YES;
|
|
_progress.backgroundColor = TImageMessageCell_Progress_Color;
|
|
[_progress.layer setMasksToBounds:YES];
|
|
[self.container addSubview:_progress];
|
|
_progress.mm_fill();
|
|
_progress.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)fillWithData:(TUIImageMessageCellData *)data;
|
|
{
|
|
//set data
|
|
[super fillWithData:data];
|
|
self.imageData = data;
|
|
_thumb.image = nil;
|
|
if(data.thumbImage == nil) {
|
|
[data downloadImage:TImage_Type_Thumb];
|
|
}
|
|
|
|
@weakify(self)
|
|
[[RACObserve(data, thumbImage) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(UIImage *thumbImage) {
|
|
@strongify(self)
|
|
if (thumbImage) {
|
|
self.thumb.image = thumbImage;
|
|
}
|
|
}];
|
|
|
|
if (data.direction == MsgDirectionIncoming) {
|
|
[[[RACObserve(data, thumbProgress) takeUntil:self.rac_prepareForReuseSignal] distinctUntilChanged] subscribeNext:^(NSNumber *x) {
|
|
@strongify(self)
|
|
int progress = [x intValue];
|
|
self.progress.text = [NSString stringWithFormat:@"%d%%", progress];
|
|
self.progress.hidden = (progress >= 100 || progress == 0);
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (void)highlightWhenMatchKeyword:(NSString *)keyword
|
|
{
|
|
// 默认高亮效果,闪烁
|
|
if (keyword) {
|
|
// 显示高亮动画
|
|
if (self.highlightAnimating) {
|
|
return;
|
|
}
|
|
[self animate:3];
|
|
}
|
|
}
|
|
|
|
// 默认高亮动画
|
|
- (void)animate:(int)times
|
|
{
|
|
times--;
|
|
if (times < 0) {
|
|
[self.animateHighlightView removeFromSuperview];
|
|
self.highlightAnimating = NO;
|
|
return;
|
|
}
|
|
self.highlightAnimating = YES;
|
|
self.animateHighlightView.frame = self.thumb.bounds;
|
|
self.animateHighlightView.alpha = 0.1;
|
|
[self.thumb addSubview:self.animateHighlightView];
|
|
[UIView animateWithDuration:0.25 animations:^{
|
|
self.animateHighlightView.alpha = 0.5;
|
|
} completion:^(BOOL finished) {
|
|
[UIView animateWithDuration:0.25 animations:^{
|
|
self.animateHighlightView.alpha = 0.1;
|
|
} completion:^(BOOL finished) {
|
|
if (!self.imageData.highlightKeyword) {
|
|
[self animate:0];
|
|
return;
|
|
}
|
|
[self animate:times];
|
|
}];
|
|
}];
|
|
}
|
|
|
|
- (UIView *)animateHighlightView
|
|
{
|
|
if (_animateHighlightView == nil) {
|
|
_animateHighlightView = [[UIView alloc] init];
|
|
_animateHighlightView.backgroundColor = [UIColor orangeColor];
|
|
}
|
|
return _animateHighlightView;
|
|
}
|
|
|
|
@end
|