WFCUVideoCell.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. @interface WFCUVideoCell ()
  11. @property(nonatomic, strong) UIImageView *shadowMaskView;
  12. @end
  13. @implementation WFCUVideoCell
  14. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  15. WFCCVideoMessageContent *imgContent = (WFCCVideoMessageContent *)msgModel.message.content;
  16. CGSize size = imgContent.thumbnail.size;
  17. if (size.height > width || size.width > width) {
  18. float scale = MIN(width/size.height, width/size.width);
  19. size = CGSizeMake(size.width * scale, size.height * scale);
  20. }
  21. return size;
  22. }
  23. - (void)setModel:(WFCUMessageModel *)model {
  24. [super setModel:model];
  25. WFCCVideoMessageContent *imgContent = (WFCCVideoMessageContent *)model.message.content;
  26. self.thumbnailView.frame = self.bubbleView.bounds;
  27. self.thumbnailView.image = imgContent.thumbnail;
  28. self.videoCoverView.frame = CGRectMake((self.bubbleView.bounds.size.width - 80)/2, (self.bubbleView.bounds.size.height - 80)/2, 80, 80);
  29. self.videoCoverView.image = [UIImage imageNamed:@"video_msg_cover"];
  30. }
  31. - (UIImageView *)thumbnailView {
  32. if (!_thumbnailView) {
  33. _thumbnailView = [[UIImageView alloc] init];
  34. [self.bubbleView addSubview:_thumbnailView];
  35. }
  36. return _thumbnailView;
  37. }
  38. - (UIImageView *)videoCoverView {
  39. if (!_videoCoverView) {
  40. _videoCoverView = [[UIImageView alloc] init];
  41. _videoCoverView.backgroundColor = [UIColor clearColor];
  42. [self.bubbleView addSubview:_videoCoverView];
  43. }
  44. return _videoCoverView;
  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. @end