123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // MyStyleVideoCell.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/11.
- //
- #import "MyStyleVideoCell.h"
- #import "MyStyleVideoView.h"
- #import "MyStyleVideoChooseView.h"
- @interface MyStyleVideoCell ()
- @property (weak, nonatomic) IBOutlet UIView *videoContainer;
- @property (nonatomic, copy) NSMutableArray *videoArray;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *containerHeight;
- @property (nonatomic, copy) StyleVideoCellAction callback;
- @end
- @implementation MyStyleVideoCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- - (void)opreationCallback:(StyleVideoCellAction)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (void)configWithSource:(NSMutableArray *)videoArray {
- [self.videoContainer removeAllSubViews];
- self.videoArray = videoArray;
-
- CGFloat viewWidth = (kScreenWidth - 14 * 2) / 2.0f;
- CGFloat height = 128.0f;
- CGFloat xPosition = 0.0f;
- CGFloat yPosition = 0.0f;
- for (NSInteger i = 0; i < videoArray.count; i++) {
- StyleVideoModel *model = self.videoArray[i];
- if (i % 2 == 0 && i != 0) {
- yPosition += height;
- xPosition = 0.0f;
- }
- MyStyleVideoView *videoView = [MyStyleVideoView shareInstance];
- videoView.frame = CGRectMake(xPosition, yPosition, viewWidth, height);
- videoView.tag = i + 1000;
- [self.videoContainer addSubview:videoView];
- [videoView configWithSource:model];
- MJWeakSelf;
- [videoView videoOperationAcion:^(STYLEVIDEO type, MyStyleVideoView * _Nonnull videoView) {
- [weakSelf previewVideoAction:type inView:videoView];
- }];
- xPosition += viewWidth;
- }
-
- if (videoArray.count < 5) {
- if (videoArray.count % 2 == 0 && videoArray.count != 0) {
- yPosition += height;
- xPosition = 0.0f;
- }
- MyStyleVideoChooseView *view = [[MyStyleVideoChooseView alloc] initWithFrame:CGRectMake(xPosition, yPosition, viewWidth, height)];
- MJWeakSelf;
- [view chooseCallback:^{
- [weakSelf chooseVideo];
- }];
- [self.videoContainer addSubview:view];
- }
-
- self.containerHeight.constant = yPosition + height;
- }
- - (void)previewVideoAction:(STYLEVIDEO)type inView:(MyStyleVideoView *)displayView {
- if (self.callback) {
- self.callback(type, displayView);
- }
- }
- - (void)chooseVideo {
- if (self.callback) {
- self.callback(STYLEVIDEO_CHOOSEFILE, nil);
- }
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|