2
0

WFCUImageCell.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // ImageCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/2.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUImageCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <SDWebImage/SDWebImage.h>
  11. @interface WFCUImageCell ()
  12. @property(nonatomic, strong) UIImageView *shadowMaskView;
  13. @end
  14. @implementation WFCUImageCell
  15. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  16. WFCCImageMessageContent *imgContent = (WFCCImageMessageContent *)msgModel.message.content;
  17. CGSize size = CGSizeMake(120, 120);
  18. if(imgContent.thumbnail) {
  19. size = imgContent.thumbnail.size;
  20. } else {
  21. size = [WFCCUtilities imageScaleSize:imgContent.size targetSize:CGSizeMake(120, 120) thumbnailPoint:nil];
  22. }
  23. if (size.height > width || size.width > width) {
  24. float scale = MIN(width/size.height, width/size.width);
  25. size = CGSizeMake(size.width * scale, size.height * scale);
  26. }
  27. return size;
  28. }
  29. - (void)setModel:(WFCUMessageModel *)model {
  30. [super setModel:model];
  31. WFCCImageMessageContent *imgContent = (WFCCImageMessageContent *)model.message.content;
  32. self.thumbnailView.frame = self.bubbleView.bounds;
  33. if (!imgContent.thumbnail && imgContent.thumbParameter) {
  34. [self.thumbnailView sd_setImageWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"%@?%@", imgContent.remoteUrl, imgContent.thumbParameter] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
  35. } else {
  36. self.thumbnailView.image = imgContent.thumbnail;
  37. }
  38. }
  39. - (UIImageView *)thumbnailView {
  40. if (!_thumbnailView) {
  41. _thumbnailView = [[UIImageView alloc] init];
  42. [self.bubbleView addSubview:_thumbnailView];
  43. }
  44. return _thumbnailView;
  45. }
  46. - (void)setMaskImage:(UIImage *)maskImage{
  47. [super setMaskImage:maskImage];
  48. if (_shadowMaskView) {
  49. [_shadowMaskView removeFromSuperview];
  50. }
  51. _shadowMaskView = [[UIImageView alloc] initWithImage:maskImage];
  52. CGRect frame = CGRectMake(self.bubbleView.frame.origin.x - 1, self.bubbleView.frame.origin.y - 1, self.bubbleView.frame.size.width + 2, self.bubbleView.frame.size.height + 2);
  53. _shadowMaskView.frame = frame;
  54. [self.contentView addSubview:_shadowMaskView];
  55. [self.contentView bringSubviewToFront:self.bubbleView];
  56. }
  57. - (UIView *)getProgressParentView {
  58. return self.thumbnailView;
  59. }
  60. @end