NIMSessionImageContentView.m 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // NIMSessionImageContentView.m
  3. // NIMKit
  4. //
  5. // Created by chris on 15/1/28.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NIMSessionImageContentView.h"
  9. #import "NIMMessageModel.h"
  10. #import "UIView+NIM.h"
  11. #import "NIMLoadProgressView.h"
  12. @interface NIMSessionImageContentView()
  13. @property (nonatomic,strong,readwrite) UIImageView * imageView;
  14. @property (nonatomic,strong) NIMLoadProgressView * progressView;
  15. @end
  16. @implementation NIMSessionImageContentView
  17. - (instancetype)initSessionMessageContentView{
  18. self = [super initSessionMessageContentView];
  19. if (self) {
  20. self.opaque = YES;
  21. _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  22. _imageView.backgroundColor = [UIColor blackColor];
  23. _imageView.contentMode = UIViewContentModeScaleAspectFill;
  24. [self addSubview:_imageView];
  25. _progressView = [[NIMLoadProgressView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
  26. _progressView.maxProgress = 1.0f;
  27. [self addSubview:_progressView];
  28. }
  29. return self;
  30. }
  31. - (void)refresh:(NIMMessageModel *)data
  32. {
  33. [super refresh:data];
  34. NIMImageObject * imageObject = (NIMImageObject*)self.model.message.messageObject;
  35. UIImage * image = [UIImage imageWithContentsOfFile:imageObject.thumbPath];
  36. self.imageView.image = image;
  37. CGSize contentSize = [data contentSize:self.superview.nim_width];
  38. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  39. self.frame = CGRectMake(contentInsets.left, contentInsets.top,contentSize.width, contentSize.height);
  40. self.imageView.frame = self.frame;
  41. //设置气泡为空
  42. [self.bubbleImageView setImage:nil];
  43. [self.bubbleImageView setHighlightedImage:nil];
  44. //设置遮罩
  45. UIImageView* maskImageView = [[UIImageView alloc]init];
  46. [maskImageView setImage:[self chatBubbleImageForState:UIControlStateNormal outgoing:data.message.isOutgoingMsg]];
  47. maskImageView.frame = self.frame;
  48. self.imageView.maskView = maskImageView;
  49. self.progressView.hidden = self.model.message.isOutgoingMsg ? (self.model.message.deliveryState != NIMMessageDeliveryStateDelivering) : (self.model.message.attachmentDownloadState != NIMMessageAttachmentDownloadStateDownloading);
  50. if (!self.progressView.hidden) {
  51. [self.progressView setProgress:[[[NIMSDK sharedSDK] chatManager] messageTransportProgress:self.model.message]];
  52. }
  53. }
  54. - (void)layoutSubviews{
  55. [super layoutSubviews];
  56. UIEdgeInsets contentInsets = self.model.contentViewInsets;
  57. CGFloat tableViewWidth = self.superview.nim_width;
  58. CGSize contentSize = [self.model contentSize:tableViewWidth];
  59. CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentSize.width, contentSize.height);
  60. self.imageView.frame = imageViewFrame;
  61. self.imageView.maskView.frame = imageViewFrame;
  62. _progressView.frame = self.bounds;
  63. // CALayer *maskLayer = [CALayer layer];
  64. // maskLayer.cornerRadius = 13.0;
  65. // maskLayer.backgroundColor = [UIColor blackColor].CGColor;
  66. // maskLayer.frame = self.imageView.bounds;
  67. // self.imageView.layer.mask = maskLayer;
  68. }
  69. - (void)onTouchUpInside:(id)sender
  70. {
  71. NIMKitEvent *event = [[NIMKitEvent alloc] init];
  72. event.eventName = NIMKitEventNameTapContent;
  73. event.messageModel = self.model;
  74. [self.delegate onCatchEvent:event];
  75. }
  76. - (void)updateProgress:(float)progress
  77. {
  78. if (progress > 1.0) {
  79. progress = 1.0;
  80. }
  81. self.progressView.progress = progress;
  82. }
  83. @end