312 lines
14 KiB
Objective-C
312 lines
14 KiB
Objective-C
//
|
|
// QXFriendCPView.m
|
|
// IsLandVoice
|
|
//
|
|
// Created by 启星 on 2025/3/10.
|
|
//
|
|
|
|
#import "QXFriendCPView.h"
|
|
#import <SVGA.h>
|
|
#import "QXMineNetwork.h"
|
|
|
|
@class QXFriendCPTypeCell;
|
|
@interface QXFriendCPView()<UICollectionViewDelegate,UICollectionViewDataSource>
|
|
|
|
@property (nonatomic,strong)UIView *bgView;
|
|
@property (nonatomic,strong)UIImageView *bgImageView;
|
|
|
|
@property (nonatomic,strong)UIImageView *headerLeftImageView;
|
|
@property (nonatomic,strong)UILabel *headerLeftNameLabel;
|
|
@property (nonatomic,strong)UIImageView *lineImageView;
|
|
/// 心动值
|
|
@property (nonatomic,strong)UILabel *heartValueLabel;
|
|
@property (nonatomic,strong)UIImageView *headerRightImageView;
|
|
@property (nonatomic,strong)UILabel *headerRightNameLabel;
|
|
|
|
@property (nonatomic,strong)UILabel *titleLabel;
|
|
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
|
|
@property (nonatomic,strong)UIButton *cancelBtn;
|
|
@property (nonatomic,strong)UIButton *commitBtn;
|
|
|
|
@property (nonatomic,assign)NSInteger selectedIndex;
|
|
|
|
@property (nonatomic, strong) SVGAPlayer *svgaPlayer;
|
|
@property (nonatomic , strong) SVGAParser *parser;
|
|
|
|
@end
|
|
@implementation QXFriendCPView
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
[self createViews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)createViews{
|
|
self.selectedIndex = -1;
|
|
|
|
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake((self.width-ScaleWidth(275))/2.0,-SCREEN_HEIGHT, ScaleWidth(275), ScaleWidth(466))];
|
|
[self addSubview:self.bgView];
|
|
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_friend_create_relation_bg"]];
|
|
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
|
|
self.bgImageView.frame = self.bgView.bounds;
|
|
[self.bgView addSubview:self.bgImageView];
|
|
[self.bgView addSubview:self.headerLeftImageView];
|
|
[self.bgView addSubview:self.headerLeftNameLabel];
|
|
[self.bgView addSubview:self.headerRightImageView];
|
|
[self.bgView addSubview:self.headerRightNameLabel];
|
|
[self.bgView addSubview:self.lineImageView];
|
|
[self.bgView addSubview:self.heartValueLabel];
|
|
|
|
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, self.headerLeftNameLabel.bottom+15, 200, 24)];
|
|
self.titleLabel.text = @"关系列表";
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
self.titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
|
[self.bgView addSubview:self.titleLabel];
|
|
|
|
self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(16, ScaleWidth(466)-42-40, (self.bgView.width-16*3-18)/2.0, 42)];
|
|
self.cancelBtn.backgroundColor = [UIColor colorWithHexString:@"#333333"];
|
|
[self.cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
|
|
self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.cancelBtn setTitleColor:[UIColor colorWithHexString:@"#ffffff"] forState:(UIControlStateNormal)];
|
|
[self.cancelBtn addTarget:self action:@selector(closeAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
self.cancelBtn.layer.masksToBounds = YES;
|
|
self.cancelBtn.layer.cornerRadius = 21;
|
|
[self.bgView addSubview:self.cancelBtn];
|
|
|
|
self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.cancelBtn.right+20, self.cancelBtn.top, self.cancelBtn.width, 42)];
|
|
self.commitBtn.backgroundColor = QXConfig.themeColor;
|
|
[self.commitBtn setTitle:@"确认" forState:(UIControlStateNormal)];
|
|
self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
[self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
|
[self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
self.commitBtn.layer.masksToBounds = YES;
|
|
self.commitBtn.layer.cornerRadius = 21;
|
|
[self.bgView addSubview:self.commitBtn];
|
|
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
CGFloat itemWidth = (self.bgView.width - 48 - 3*12)/3.0;
|
|
layout.itemSize = CGSizeMake(itemWidth, 34);
|
|
layout.minimumInteritemSpacing = 12;
|
|
layout.minimumLineSpacing = 12;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 18, 0, 30);
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+10, self.bgView.width, self.commitBtn.top-self.titleLabel.bottom-30) collectionViewLayout:layout];
|
|
self.collectionView.delegate = self;
|
|
self.collectionView.backgroundColor = [UIColor clearColor];
|
|
self.collectionView.dataSource = self;
|
|
[self.collectionView registerClass:[QXFriendCPTypeCell class] forCellWithReuseIdentifier:@"QXFriendCPTypeCell"];
|
|
[self.bgView addSubview:self.collectionView];
|
|
[self getRelationShipList];
|
|
}
|
|
-(void)getRelationShipList{
|
|
MJWeakSelf
|
|
[QXMineNetwork roomRelationListWithType:@"2" successBlock:^(NSArray<QXRoomRelationModel *> * _Nonnull list) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
[weakSelf.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
}];
|
|
}
|
|
-(void)setModel:(QXRoomFriendRelationModel *)model{
|
|
_model = model;
|
|
[self.headerLeftImageView sd_setImageWithURL:[NSURL URLWithString:model.user1_avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
|
[self.headerRightImageView sd_setImageWithURL:[NSURL URLWithString:model.user2_avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
|
|
|
self.headerLeftNameLabel.text = model.user1_nickname;
|
|
self.headerRightNameLabel.text = model.user2_nickname;
|
|
|
|
self.heartValueLabel.text = model.heart_value;
|
|
}
|
|
|
|
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
|
return 1;
|
|
}
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.dataArray.count;
|
|
}
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXFriendCPTypeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXFriendCPTypeCell" forIndexPath:indexPath];
|
|
QXRoomRelationModel *model = self.dataArray[indexPath.row];
|
|
cell.title = model.name;
|
|
if (indexPath.row == self.selectedIndex) {
|
|
cell.isSelected = YES;
|
|
}else{
|
|
cell.isSelected = NO;
|
|
}
|
|
return cell;
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
self.selectedIndex = indexPath.row;
|
|
[self.collectionView reloadData];
|
|
}
|
|
|
|
-(void)commitAction{
|
|
// QXFriendCPSuccessView *successView = [[QXFriendCPSuccessView alloc] init];
|
|
// for (UIWindow *w in [UIApplication sharedApplication].windows) {
|
|
// if ([w isKeyWindow]) {
|
|
// [successView showInView:w];
|
|
// break;
|
|
// }
|
|
// }
|
|
QXRoomRelationModel *md = self.dataArray[self.selectedIndex];
|
|
if (self.commitBlock) {
|
|
self.commitBlock(self.model,md.relation_id,md.name);
|
|
}
|
|
}
|
|
|
|
-(void)closeAction{
|
|
[self hide];
|
|
}
|
|
|
|
-(void)showInView:(UIView *)view{
|
|
[view addSubview:self];
|
|
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
|
self.bgView.centerY = self.centerY;
|
|
} completion:^(BOOL finished) {
|
|
|
|
}];
|
|
}
|
|
|
|
-(void)hide{
|
|
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|
} completion:^(BOOL finished) {
|
|
[self removeFromSuperview];
|
|
}];
|
|
}
|
|
- (UIImageView *)headerLeftImageView{
|
|
if (!_headerLeftImageView) {
|
|
_headerLeftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(18, ScaleWidth(130), ScaleWidth(50), ScaleWidth(50))];
|
|
_headerLeftImageView.image = [UIImage imageNamed:@"user_header_placehoulder"];
|
|
_headerLeftImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_headerLeftImageView.layer.masksToBounds = YES;
|
|
_headerLeftImageView.layer.cornerRadius = ScaleWidth(50)/2.0;
|
|
}
|
|
return _headerLeftImageView;
|
|
}
|
|
-(UILabel *)headerLeftNameLabel{
|
|
if (!_headerLeftNameLabel) {
|
|
_headerLeftNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headerLeftImageView.left, self.headerLeftImageView.bottom, 100, 20)];
|
|
_headerLeftNameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
|
_headerLeftNameLabel.font = [UIFont systemFontOfSize:12];
|
|
_headerLeftNameLabel.textAlignment = NSTextAlignmentLeft;
|
|
}
|
|
return _headerLeftNameLabel;
|
|
}
|
|
- (UIImageView *)headerRightImageView{
|
|
if (!_headerRightImageView) {
|
|
_headerRightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.bgView.width-30-ScaleWidth(50), self.headerLeftImageView.top, ScaleWidth(50), ScaleWidth(50))];
|
|
_headerRightImageView.image = [UIImage imageNamed:@"user_header_placehoulder"];
|
|
_headerRightImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_headerRightImageView.layer.masksToBounds = YES;
|
|
_headerRightImageView.layer.cornerRadius = ScaleWidth(50)/2.0;
|
|
}
|
|
return _headerRightImageView;
|
|
}
|
|
-(UILabel *)headerRightNameLabel{
|
|
if (!_headerRightNameLabel) {
|
|
_headerRightNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headerRightImageView.right-100, self.headerLeftImageView.bottom, 100, 20)];
|
|
_headerRightNameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
|
|
_headerRightNameLabel.font = [UIFont systemFontOfSize:12];
|
|
_headerRightNameLabel.textAlignment = NSTextAlignmentRight;
|
|
}
|
|
return _headerRightNameLabel;
|
|
}
|
|
-(UIImageView *)lineImageView{
|
|
if (!_lineImageView) {
|
|
_lineImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_friend_relation_heart"]];
|
|
_lineImageView.frame = CGRectMake(self.headerLeftImageView.right, 0, self.headerRightImageView.left-self.headerLeftImageView.right, ScaleWidth(50));
|
|
_lineImageView.centerY = self.headerLeftImageView.centerY;
|
|
}
|
|
return _lineImageView;
|
|
}
|
|
- (UILabel *)heartValueLabel{
|
|
if (!_heartValueLabel) {
|
|
_heartValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 18)];
|
|
_heartValueLabel.centerY = self.lineImageView.centerY;
|
|
_heartValueLabel.centerX = self.lineImageView.centerX;
|
|
_heartValueLabel.backgroundColor = [UIColor colorWithHexString:@"#FE8EC8"];
|
|
_heartValueLabel.layer.masksToBounds = YES;
|
|
_heartValueLabel.layer.cornerRadius = 9;
|
|
_heartValueLabel.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_heartValueLabel.layer.borderWidth = 1;
|
|
_heartValueLabel.textColor = [UIColor whiteColor];
|
|
_heartValueLabel.textAlignment = NSTextAlignmentCenter;
|
|
_heartValueLabel.font = [UIFont boldSystemFontOfSize:12];
|
|
}
|
|
return _heartValueLabel;
|
|
}
|
|
-(NSMutableArray *)dataArray{
|
|
if (!_dataArray) {
|
|
_dataArray = [NSMutableArray array];
|
|
}
|
|
return _dataArray;
|
|
}
|
|
@end
|
|
|
|
|
|
@implementation QXFriendCPTypeCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self createViews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)setIsSelected:(BOOL)isSelected{
|
|
_isSelected = isSelected;
|
|
self.titleBtn.selected = isSelected;
|
|
if (self.isSelected) {
|
|
self.titleBtn.titleLabel.font = [UIFont systemFontOfSize:16];
|
|
}else{
|
|
self.titleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
}
|
|
}
|
|
-(void)setType:(NSInteger)type{
|
|
_type = type;
|
|
if (type == 1) {
|
|
self.titleBtn.layer.cornerRadius = 17;
|
|
UIImage *normalImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#F6F6F6"]];
|
|
[self.titleBtn setBackgroundImage:normalImage forState:(UIControlStateNormal)];
|
|
}if (type == 2){
|
|
self.titleBtn.layer.cornerRadius = 0;
|
|
[self.titleBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
|
|
[self.titleBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:(UIControlStateNormal)];
|
|
[self.titleBtn setTitleColor:[UIColor colorWithHexString:@"#ffffff"] forState:(UIControlStateSelected)];
|
|
[self.titleBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
|
|
[self.titleBtn setBackgroundImage:nil forState:(UIControlStateSelected)];
|
|
self.titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
|
}
|
|
}
|
|
-(void)setTitle:(NSString *)title{
|
|
_title = title;
|
|
[self.titleBtn setTitle:title forState:(UIControlStateNormal)];
|
|
}
|
|
-(void)createViews{
|
|
self.titleBtn = [[UIButton alloc] init];
|
|
UIImage *selectedImage = [UIImage imageWithColor:QXConfig.themeColor];
|
|
UIImage *normalImage = [UIImage imageWithColor:[UIColor colorWithHexString:@"#FFFFFF"]];
|
|
[self.titleBtn setBackgroundImage:selectedImage forState:(UIControlStateSelected)];
|
|
[self.titleBtn setBackgroundImage:normalImage forState:(UIControlStateNormal)];
|
|
[self.titleBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:(UIControlStateNormal)];
|
|
[self.titleBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateSelected)];
|
|
self.titleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
self.titleBtn.layer.masksToBounds = YES;
|
|
self.titleBtn.layer.cornerRadius = 4;
|
|
[self.contentView addSubview:self.titleBtn];
|
|
self.titleBtn.userInteractionEnabled = NO;
|
|
[self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.bottom.equalTo(self.contentView);
|
|
}];
|
|
}
|
|
|
|
@end
|