123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // NIMSessionVideoContentView.m
- // NIMKit
- //
- // Created by chris on 15/4/10.
- // Copyright (c) 2015年 Netease. All rights reserved.
- //
- #import "NIMSessionVideoContentView.h"
- #import "NIMMessageModel.h"
- #import "UIView+NIM.h"
- #import "UIImage+NIMKit.h"
- #import "NIMLoadProgressView.h"
- @interface NIMSessionVideoContentView()
- @property (nonatomic,strong,readwrite) UIImageView * imageView;
- @property (nonatomic,strong) UIButton *playBtn;
- @property (nonatomic,strong) NIMLoadProgressView * progressView;
- @end
- @implementation NIMSessionVideoContentView
- - (instancetype)initSessionMessageContentView{
- self = [super initSessionMessageContentView];
- if (self) {
- self.opaque = YES;
- _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
- _imageView.backgroundColor = [UIColor blackColor];
- [self addSubview:_imageView];
-
- _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_playBtn setImage:[UIImage nim_imageInKit:@"icon_play_normal"] forState:UIControlStateNormal];
- [_playBtn sizeToFit];
- [_playBtn setUserInteractionEnabled:NO];
- [self addSubview:_playBtn];
-
- _progressView = [[NIMLoadProgressView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
- _progressView.maxProgress = 1.0;
- [self addSubview:_progressView];
- }
- return self;
- }
- - (void)refresh:(NIMMessageModel *)data{
- [super refresh:data];
- NIMVideoObject * videoObject = (NIMVideoObject*)self.model.message.messageObject;
- UIImage * image = [UIImage imageWithContentsOfFile:videoObject.coverPath];
- self.imageView.image = image;
- CGSize contentSize = [data contentSize:self.superview.nim_width];
- self.bounds = CGRectMake(0, 0,contentSize.width, contentSize.height);
- self.imageView.frame = self.bounds;
- //设置气泡为空
- [self.bubbleImageView setImage:nil];
- [self.bubbleImageView setHighlightedImage:nil];
- //设置遮罩
- UIImageView* maskImageView = [[UIImageView alloc]init];
- [maskImageView setImage:[self chatBubbleImageForState:UIControlStateNormal outgoing:data.message.isOutgoingMsg]];
- maskImageView.frame = self.bounds;
- self.imageView.maskView = maskImageView;
- _progressView.hidden = (self.model.message.deliveryState != NIMMessageDeliveryStateDelivering);
- if (!_progressView.hidden) {
- [_progressView setProgress:[[[NIMSDK sharedSDK] chatManager] messageTransportProgress:self.model.message]];
- }
- }
- - (void)layoutSubviews{
- [super layoutSubviews];
- UIEdgeInsets contentInsets = self.model.contentViewInsets;
-
- CGFloat tableViewWidth = self.superview.nim_width;
- CGSize contentsize = [self.model contentSize:tableViewWidth];
-
- CGRect imageViewFrame = CGRectMake(contentInsets.left, contentInsets.top, contentsize.width, contentsize.height);
- self.imageView.frame = imageViewFrame;
- self.imageView.maskView.frame = imageViewFrame;
- _progressView.frame = self.bounds;
-
- // CALayer *maskLayer = [CALayer layer];
- // maskLayer.cornerRadius = 13.0;
- // maskLayer.backgroundColor = [UIColor blackColor].CGColor;
- // maskLayer.frame = self.imageView.bounds;
- // self.imageView.layer.mask = maskLayer;
-
- self.playBtn.nim_centerX = self.nim_width * .5f;
- self.playBtn.nim_centerY = self.nim_height * .5f;
- }
- - (void)onTouchUpInside:(id)sender
- {
- NIMKitEvent *event = [[NIMKitEvent alloc] init];
- event.eventName = NIMKitEventNameTapContent;
- event.messageModel = self.model;
- [self.delegate onCatchEvent:event];
- }
- - (void)updateProgress:(float)progress
- {
- if (progress > 1.0) {
- progress = 1.0;
- }
- self.progressView.progress = progress;
- }
- @end
|