WFCUVideoCell.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // VideoCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/2.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUVideoCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUImage.h"
  11. @interface WFCUVideoCell ()
  12. @property(nonatomic, strong) UIImageView *shadowMaskView;
  13. @end
  14. @implementation WFCUVideoCell
  15. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  16. WFCCVideoMessageContent *imgContent = (WFCCVideoMessageContent *)msgModel.message.content;
  17. CGSize size = imgContent.thumbnail.size;
  18. if (size.height > width || size.width > width) {
  19. float scale = MIN(width/size.height, width/size.width);
  20. size = CGSizeMake(size.width * scale, size.height * scale);
  21. }
  22. return size;
  23. }
  24. - (void)setModel:(WFCUMessageModel *)model {
  25. [super setModel:model];
  26. WFCCVideoMessageContent *imgContent = (WFCCVideoMessageContent *)model.message.content;
  27. self.thumbnailView.frame = self.bubbleView.bounds;
  28. self.thumbnailView.image = imgContent.thumbnail;
  29. self.videoCoverView.frame = CGRectMake((self.bubbleView.bounds.size.width - 40)/2, (self.bubbleView.bounds.size.height - 40)/2, 40, 40);
  30. self.videoCoverView.image = [WFCUImage imageNamed:@"video_msg_cover"];
  31. }
  32. - (UIImageView *)thumbnailView {
  33. if (!_thumbnailView) {
  34. _thumbnailView = [[UIImageView alloc] init];
  35. [self.bubbleView addSubview:_thumbnailView];
  36. }
  37. return _thumbnailView;
  38. }
  39. - (UIImageView *)videoCoverView {
  40. if (!_videoCoverView) {
  41. _videoCoverView = [[UIImageView alloc] init];
  42. _videoCoverView.backgroundColor = [UIColor clearColor];
  43. [self.bubbleView addSubview:_videoCoverView];
  44. }
  45. return _videoCoverView;
  46. }
  47. - (void)setMaskImage:(UIImage *)maskImage{
  48. [super setMaskImage:maskImage];
  49. if (_shadowMaskView) {
  50. [_shadowMaskView removeFromSuperview];
  51. }
  52. _shadowMaskView = [[UIImageView alloc] initWithImage:maskImage];
  53. 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);
  54. _shadowMaskView.frame = frame;
  55. [self.contentView addSubview:_shadowMaskView];
  56. [self.contentView bringSubviewToFront:self.bubbleView];
  57. }
  58. - (UIView *)getProgressParentView {
  59. return self.thumbnailView;
  60. }
  61. @end