EMMsgExtGifBubbleView.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // EMMsgExtGifBubbleView.m
  3. // ChatDemo-UI3.0
  4. //
  5. // Created by XieYajie on 2019/2/14.
  6. // Copyright © 2019 XieYajie. All rights reserved.
  7. //
  8. #import "EMMsgExtGifBubbleView.h"
  9. #import "EMEmoticonGroup.h"
  10. @implementation EMMsgExtGifBubbleView
  11. - (instancetype)initWithDirection:(EMMessageDirection)aDirection
  12. type:(EMMessageType)aType
  13. {
  14. self = [super initWithDirection:aDirection type:aType];
  15. if (self) {
  16. self.gifView = [[FLAnimatedImageView alloc] init];
  17. [self addSubview:self.gifView];
  18. [self.gifView mas_makeConstraints:^(MASConstraintMaker *make) {
  19. make.edges.equalTo(self);
  20. make.width.height.lessThanOrEqualTo(@100);
  21. }];
  22. }
  23. return self;
  24. }
  25. #pragma mark - Setter
  26. - (void)setModel:(EMMessageModel *)model
  27. {
  28. EMMessageType type = model.type;
  29. if (type == EMMessageTypeExtGif) {
  30. NSString *name = [(EMTextMessageBody *)model.emModel.body text];
  31. EMEmoticonGroup *group = [EMEmoticonGroup getGifGroup];
  32. for (EMEmoticonModel *model in group.dataArray) {
  33. if ([model.name isEqualToString:name]) {
  34. NSString *path = [[NSBundle mainBundle] pathForResource:model.original ofType:@"gif"];
  35. NSData *imageData = [NSData dataWithContentsOfFile:path];
  36. self.gifView.animatedImage = [FLAnimatedImage animatedImageWithGIFData:imageData];;
  37. break;
  38. }
  39. }
  40. }
  41. }
  42. @end