79 lines
2.3 KiB
Objective-C
79 lines
2.3 KiB
Objective-C
//
|
|
// SCLiveItemContainerView.m
|
|
// SellyCloudSDK_Example
|
|
//
|
|
// Created by Caleb on 21/7/25.
|
|
// Copyright © 2025 Caleb. All rights reserved.
|
|
//
|
|
|
|
#import "SCLiveItemContainerView.h"
|
|
#import "SCLiveItemView.h"
|
|
|
|
@interface SCLiveItemContainerView ()
|
|
@property (nonatomic, strong)NSMutableArray<SCLiveItemView *> *itemViews;
|
|
@property (nonatomic, strong)UIVisualEffectView *blurView;
|
|
@end
|
|
|
|
@implementation SCLiveItemContainerView
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
// 使用毛玻璃效果背景
|
|
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
|
_blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
|
_blurView.layer.cornerRadius = 20;
|
|
_blurView.layer.masksToBounds = YES;
|
|
[self addSubview:_blurView];
|
|
|
|
// 添加轻微的边框
|
|
self.layer.cornerRadius = 20;
|
|
self.layer.borderWidth = 0.5;
|
|
self.layer.borderColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2].CGColor;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
_blurView.frame = self.bounds;
|
|
}
|
|
|
|
- (void)setModels:(NSArray<SCLiveItemModel *> *)models {
|
|
_models = models;
|
|
|
|
[self.itemViews enumerateObjectsUsingBlock:^(SCLiveItemView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
[obj removeFromSuperview];
|
|
}];
|
|
[self.itemViews removeAllObjects];
|
|
|
|
for (NSInteger i = 0; i<models.count; i++) {
|
|
SCLiveItemView *itemView = SCLiveItemView.new;
|
|
itemView.model = models[i];
|
|
[self.itemViews addObject:itemView];
|
|
[self addSubview:itemView];
|
|
}
|
|
|
|
if (self.itemViews.count) {
|
|
// 使用固定间距和自适应宽度
|
|
[self.itemViews mas_distributeViewsAlongAxis:MASAxisTypeHorizontal
|
|
withFixedSpacing:12
|
|
leadSpacing:20
|
|
tailSpacing:20];
|
|
[self.itemViews mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.offset(64);
|
|
make.centerY.offset(0);
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (NSMutableArray<SCLiveItemView *> *)itemViews {
|
|
if (!_itemViews) {
|
|
_itemViews = NSMutableArray.array;
|
|
}
|
|
return _itemViews;
|
|
}
|
|
|
|
@end
|