Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeHotRoomCollectionViewCell.m
2022-03-04 19:54:17 +08:00

265 lines
8.7 KiB
Objective-C

//
// XPHomeHotRoomCollectionViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/2/21.
//
#import "XPHomeHotRoomCollectionViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "NetImageView.h"
#import "ThemeColor.h"
#import "XPMacro.h"
#import "UIImage+Utils.h"
///Model
#import "HomeRecommendRoomModel.h"
@interface XPHomeHotRoomCollectionViewCell ()
///背景
@property (nonatomic,strong) UIImageView *backImageView;
///房间的标签
@property (nonatomic,strong) NetImageView *roomTagImageView;
///房间的话题
@property (nonatomic,strong) UILabel *roomDesLabel;
///note
@property (nonatomic,strong) UIImageView *notImageView;
///房间标题
@property (nonatomic,strong) UILabel *roomTitleLabel;
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///性别
@property (nonatomic,strong) UIImageView *sexImageView;
///昵称
@property (nonatomic,strong) UILabel *nickLabel;
///水波纹动画
@property (nonatomic,strong) UIView *rippleView;
@end
@implementation XPHomeHotRoomCollectionViewCell
- (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.backImageView];
[self.backImageView addSubview:self.rippleView];
[self.backImageView addSubview:self.roomTagImageView];
[self.backImageView addSubview:self.roomDesLabel];
[self.backImageView addSubview:self.notImageView];
[self.backImageView addSubview:self.roomTitleLabel];
[self.backImageView addSubview:self.avatarImageView];
[self.backImageView addSubview:self.sexImageView];
[self.backImageView addSubview:self.nickLabel];
[self addAnimation];
}
- (void)addAnimation {
NSInteger pulsingCount = 3;
double animationDuration = 3;
CALayer * animationLayer = [CALayer layer];
for (int i = 0; i < pulsingCount; i++) {
CALayer * pulsingLayer = [CALayer layer];
pulsingLayer.frame = CGRectMake(0, 0, 50, 50);
pulsingLayer.borderColor = [UIColor whiteColor].CGColor;
pulsingLayer.borderWidth = 1;
pulsingLayer.cornerRadius = 50 / 2;
CAMediaTimingFunction * defaultCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
CAAnimationGroup * animationGroup = [CAAnimationGroup animation];
animationGroup.fillMode = kCAFillModeBackwards;
animationGroup.beginTime = CACurrentMediaTime() + (double)i * animationDuration / (double)pulsingCount;
animationGroup.duration = animationDuration;
animationGroup.repeatCount = HUGE;
animationGroup.removedOnCompletion = NO;
animationGroup.timingFunction = defaultCurve;
CABasicAnimation * scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = @1.4;
scaleAnimation.toValue = @3;
scaleAnimation.removedOnCompletion = NO;
CAKeyframeAnimation * opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.values = @[@1, @0.9, @0.8, @0.7, @0.6, @0.5, @0.4, @0.3, @0.2, @0.1, @0];
opacityAnimation.keyTimes = @[@0, @0.1, @0.2, @0.3, @0.4, @0.5, @0.6, @0.7, @0.8, @0.9, @1];
opacityAnimation.removedOnCompletion = NO;
animationGroup.animations = @[scaleAnimation, opacityAnimation];
[pulsingLayer addAnimation:animationGroup forKey:@"plulsing"];
[animationLayer addSublayer:pulsingLayer];
}
[self.rippleView.layer addSublayer:animationLayer];
}
- (void)initSubViewConstraints {
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView).offset(-4);
}];
[self.roomTagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(38, 18));
make.left.top.mas_equalTo(self.backImageView);
}];
[self.roomDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backImageView).offset(13);
make.right.mas_equalTo(self.backImageView).offset(-4);
make.top.mas_equalTo(self.backImageView).offset(22);
}];
[self.notImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(13, 9.6));
make.top.mas_equalTo(self.roomDesLabel.mas_bottom).offset(3);
make.left.mas_equalTo(self.roomDesLabel);
}];
[self.roomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.notImageView.mas_right).offset(5);
make.centerY.mas_equalTo(self.notImageView);
make.right.mas_lessThanOrEqualTo(self.backImageView);
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(50, 50));
make.centerX.mas_equalTo(self.backImageView);
make.top.mas_equalTo(self.notImageView.mas_bottom).offset(9);
}];
[self.rippleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.avatarImageView);
make.size.mas_equalTo(CGSizeMake(50, 50));
}];
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.backImageView);
make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(3);
}];
[self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.bottom.mas_equalTo(self.avatarImageView);
make.size.mas_equalTo(CGSizeMake(14, 14));
}];
}
#pragma mark - Getters And Setters
- (void)setHotRoomInfo:(HomeRecommendRoomModel *)hotRoomInfo {
_hotRoomInfo = hotRoomInfo;
if (_hotRoomInfo) {
self.avatarImageView.imageUrl = _hotRoomInfo.avatar;
self.roomTitleLabel.text = _hotRoomInfo.title;
self.roomTagImageView.imageUrl = _hotRoomInfo.tagPict;
self.nickLabel.text = _hotRoomInfo.nick;
self.sexImageView.image = _hotRoomInfo.gender == GenderType_Female ? [UIImage imageNamed:@"common_female"] : [UIImage imageNamed:@"common_male"];
self.roomDesLabel.text = _hotRoomInfo.roomDesc;
}
}
- (void)setIndexPathRow:(NSInteger)indexPathRow {
_indexPathRow = (indexPathRow + 1);
if (_indexPathRow % 2 != 0) {
self.backImageView.image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xC0C9FF), UIColorFromRGB(0xFEDAFF)] gradientType:GradientTypeTopToBottom imgSize:CGSizeMake(10, 10)];
} else {
self.backImageView.image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFFF8D9), UIColorFromRGB(0xEAFFD8)] gradientType:GradientTypeTopToBottom imgSize:CGSizeMake(10, 10)];
}
}
- (UIImageView *)backImageView {
if (!_backImageView) {
_backImageView = [[UIImageView alloc] init];
_backImageView.contentMode = UIViewContentModeScaleAspectFill;
_backImageView.layer.masksToBounds = YES;
_backImageView.layer.cornerRadius = 8;
_backImageView.layer.shadowOffset = CGSizeMake(4, 4);
_backImageView.layer.shadowColor = UIColorRGBAlpha(0xEBEEF3, 0.7).CGColor;
}
return _backImageView;
}
- (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 = 50/2;
_avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
_avatarImageView.layer.borderWidth = 1.1;
}
return _avatarImageView;
}
- (UILabel *)roomTitleLabel {
if (!_roomTitleLabel) {
_roomTitleLabel = [[UILabel alloc] init];
_roomTitleLabel.font = [UIFont boldSystemFontOfSize:14];
_roomTitleLabel.textColor = [ThemeColor mainTextColor];
}
return _roomTitleLabel;
}
- (UILabel *)nickLabel {
if (!_nickLabel) {
_nickLabel = [[UILabel alloc] init];
_nickLabel.font = [UIFont systemFontOfSize:12];
_nickLabel.textColor = [ThemeColor mainTextColor];
_nickLabel.textAlignment = NSTextAlignmentCenter;
}
return _nickLabel;
}
- (UIImageView *)sexImageView {
if (!_sexImageView) {
_sexImageView = [[UIImageView alloc] init];
_sexImageView.userInteractionEnabled = YES;
}
return _sexImageView;
}
- (NetImageView *)roomTagImageView {
if (!_roomTagImageView) {
_roomTagImageView = [[NetImageView alloc] init];
_roomTagImageView.userInteractionEnabled = YES;
}
return _roomTagImageView;
}
- (UILabel *)roomDesLabel {
if (!_roomDesLabel) {
_roomDesLabel = [[UILabel alloc] init];
_roomDesLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
_roomDesLabel.textColor = UIColorFromRGB(0x000000);
_roomDesLabel.numberOfLines = 0.2;
}
return _roomDesLabel;
}
- (UIImageView *)notImageView {
if (!_notImageView) {
_notImageView = [[UIImageView alloc] init];
_notImageView.image = [UIImage imageNamed:@"home_recommend_hot_note"];
}
return _notImageView;
}
- (UIView *)rippleView {
if (!_rippleView) {
_rippleView = [[UIView alloc] init];
_rippleView.backgroundColor = [UIColor clearColor];
}
return _rippleView;
}
@end