154 lines
4.2 KiB
Objective-C
154 lines
4.2 KiB
Objective-C
//
|
|
// XPHomeAttentionCollectionViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/3/2.
|
|
//
|
|
|
|
#import "XPHomeAttentionCollectionViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "NetImageView.h"
|
|
#import "ThemeColor.h"
|
|
///Model
|
|
#import "HomeLiveRoomModel.h"
|
|
|
|
@interface XPHomeAttentionCollectionViewCell ()
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///昵称
|
|
@property (nonatomic,strong) UILabel *nickLabel;
|
|
///阴影
|
|
@property (nonatomic, strong) UIVisualEffectView *blurView;
|
|
///音符动销
|
|
@property (nonatomic,strong) UIImageView *noteImageView;
|
|
///动画的数组
|
|
@property (nonatomic,strong) NSArray *animationArray;
|
|
@end
|
|
|
|
@implementation XPHomeAttentionCollectionViewCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
[self.contentView addSubview:self.nickLabel];
|
|
|
|
[self.avatarImageView addSubview:self.blurView];
|
|
[self.avatarImageView addSubview:self.noteImageView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(56, 56));
|
|
make.centerX.mas_equalTo(self.contentView);
|
|
make.top.mas_equalTo(self.contentView);
|
|
}];
|
|
|
|
[self.blurView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.bottom.mas_equalTo(self.avatarImageView);
|
|
make.height.mas_equalTo(14);
|
|
}];
|
|
|
|
[self.noteImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.centerY.mas_equalTo(self.blurView);
|
|
make.height.mas_equalTo(10);
|
|
make.width.mas_equalTo(24);
|
|
}];
|
|
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.avatarImageView);
|
|
make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(4);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setLiveRoom:(HomeLiveRoomModel *)liveRoom {
|
|
_liveRoom = liveRoom;
|
|
if (_liveRoom) {
|
|
self.avatarImageView.imageUrl = _liveRoom.avatar;
|
|
self.nickLabel.text = _liveRoom.nick;
|
|
self.blurView.hidden = _liveRoom.roomUid <=0;
|
|
self.noteImageView.hidden = _liveRoom.roomUid <=0;
|
|
if (_liveRoom.roomUid > 0) {
|
|
self.noteImageView.animationImages = self.animationArray;
|
|
[self.noteImageView startAnimating];
|
|
}else {
|
|
self.noteImageView.animationImages = nil;
|
|
[self.noteImageView stopAnimating];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.layer.cornerRadius = 56/2;
|
|
_avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)nickLabel {
|
|
if (!_nickLabel) {
|
|
_nickLabel = [[UILabel alloc] init];
|
|
_nickLabel.font = [UIFont systemFontOfSize:12];
|
|
_nickLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _nickLabel;
|
|
}
|
|
|
|
- (UIVisualEffectView *)blurView {
|
|
if (!_blurView) {
|
|
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
|
|
_blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
|
|
_blurView.alpha = 0.3;
|
|
}
|
|
return _blurView;
|
|
}
|
|
|
|
- (UIImageView *)noteImageView {
|
|
if (!_noteImageView) {
|
|
_noteImageView = [[UIImageView alloc] init];
|
|
_noteImageView.userInteractionEnabled = YES;
|
|
_noteImageView.animationRepeatCount = HUGE;
|
|
_noteImageView.image = [UIImage imageNamed:@"home_note_0000"];
|
|
}
|
|
return _noteImageView;
|
|
}
|
|
|
|
- (NSArray *)animationArray {
|
|
if (!_animationArray) {
|
|
NSMutableArray * array = [NSMutableArray array];
|
|
for (int i = 0; i < 12; i++) {
|
|
NSString * imageName;
|
|
if (i> 9) {
|
|
imageName = [NSString stringWithFormat:@"home_note_000%d",i];
|
|
} else {
|
|
imageName = [NSString stringWithFormat:@"home_note_0000%d",i];
|
|
}
|
|
|
|
|
|
UIImage * image = [UIImage imageNamed:imageName];
|
|
[array addObject:image];
|
|
}
|
|
_animationArray = [array copy];
|
|
}
|
|
return _animationArray;
|
|
}
|
|
|
|
@end
|