Files
featherVoice/QXLive/Dynamic(语圈)/View/QXExpansionAppStoreView.m
2025-08-08 10:49:36 +08:00

380 lines
14 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// QXExpansionAppStoreView.m
// QXLive
//
// Created by 启星 on 2025/7/31.
//
#import "QXExpansionAppStoreView.h"
#import "CKShimmerLabel.h"
@interface QXExpansionAppStoreView()<CAAnimationDelegate>
@property (nonatomic,strong)CKShimmerLabel *titleLabel;
@property (nonatomic,strong)UIImageView *bgImageView;
@property (nonatomic,strong)UIImageView *fengcheImageView;
@property (nonatomic,strong)UIButton *changeBtn;
@property (nonatomic,strong)NSMutableArray *randomArray;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView1;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView2;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView3;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView4;
@property (nonatomic,strong)NSMutableArray *userViews;
@end
@implementation QXExpansionAppStoreView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *hitView= [super hitTest:point withEvent:event];
if (hitView== self)
{
return nil;
}
else
{
return hitView;
}
}
-(void)initSubviews{
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"expansion_bg"]];
self.bgImageView.frame = CGRectMake((self.width-375)/2, (self.height-375)/2-20, 375, 375);
[self addSubview:self.bgImageView];
// [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.height.width.mas_equalTo(375);
// make.centerX.centerY.equalTo(self);
// }];
self.titleLabel = [[CKShimmerLabel alloc] init];
self.titleLabel.shimmerWidth = 20;
self.titleLabel.shimmerRadius = 20;
self.titleLabel.shimmerColor = QXConfig.themeColor;
self.titleLabel.shimmerType = ST_LeftToRight;
self.titleLabel.repeat = YES;
self.titleLabel.textColor = RGB16(0x333333);
self.titleLabel.font = [UIFont fontWithName:@"YouSheBiaoTiHei" size:30];
self.titleLabel.text = @"风车转转转,找寻新玩伴";
self.titleLabel.top = 80;
[self.titleLabel.contentLabel sizeToFit];
self.titleLabel.width = self.titleLabel.contentLabel.width;
self.titleLabel.centerX = self.centerX;
[self.titleLabel startShimmer];
[self addSubview:self.titleLabel];
self.fengcheImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fengche"]];
self.fengcheImageView.hidden = YES;
self.fengcheImageView.frame = CGRectMake((self.width-70)/2, (self.height-70)/2-20, 70, 70);
[self.fengcheImageView addRoundedCornersWithRadius:35];
self.fengcheImageView.layer.borderWidth = 5;
self.fengcheImageView.layer.borderColor = UIColor.whiteColor.CGColor;
[self addSubview:self.fengcheImageView];
// [self.fengcheImageView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.centerY.centerX.equalTo(self.bgImageView);
// make.height.width.mas_offset(70);
// }];
self.changeBtn = [[UIButton alloc] init];
self.changeBtn.frame = self.fengcheImageView.frame;
self.changeBtn.backgroundColor = QXConfig.themeColor;
[self.changeBtn addRoundedCornersWithRadius:35];
[self.changeBtn setTitle:@"换一批" forState:(UIControlStateNormal)];
self.changeBtn.layer.borderWidth = 5;
self.changeBtn.layer.borderColor = UIColor.whiteColor.CGColor;
self.changeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[self.changeBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
[self.changeBtn addTarget:self action:@selector(changeAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.changeBtn];
// [self.changeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// make.centerY.centerX.equalTo(self.bgImageView);
// make.height.width.mas_offset(70);
// }];
self.userView1 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.bgImageView.left+40, self.bgImageView.top+28, 100, 100)];
[self addSubview:self.userView1];
// [self.userView1 mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self.bgImageView).offset(40);
// make.top.equalTo(self.bgImageView).offset(32);
// make.width.mas_equalTo(100);
// make.height.mas_equalTo(100);
// }];
self.userView2 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.bgImageView.right-40-100, self.bgImageView.top+28, 100, 100)];
[self addSubview:self.userView2];
// [self.userView2 mas_makeConstraints:^(MASConstraintMaker *make) {
// make.right.equalTo(self.bgImageView).offset(-40);
// make.top.equalTo(self.bgImageView).offset(32);
// make.width.mas_equalTo(100);
// make.height.mas_equalTo(100);
// }];
self.userView3 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.bgImageView.left+40, self.bgImageView.bottom-55-100, 100, 100)];
[self addSubview:self.userView3];
// [self.userView3 mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self.bgImageView).offset(40);
// make.bottom.equalTo(self.bgImageView).offset(-55);
// make.width.mas_equalTo(100);
// make.height.mas_equalTo(100);
// }];
self.userView4 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.bgImageView.right-40-100, self.bgImageView.bottom-55-100, 100, 100)];
[self addSubview:self.userView4];
// [self.userView4 mas_makeConstraints:^(MASConstraintMaker *make) {
// make.right.equalTo(self.bgImageView).offset(-40);
// make.bottom.equalTo(self.bgImageView).offset(-55);
// make.width.mas_equalTo(100);
// make.height.mas_equalTo(100);
// }];
[self.userViews addObject:self.userView1];
[self.userViews addObject:self.userView2];
[self.userViews addObject:self.userView3];
[self.userViews addObject:self.userView4];
MJWeakSelf
[self.userView1 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView1.model);
}
}];
[self.userView2 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView2.model);
}
}];
[self.userView3 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView3.model);
}
}];
[self.userView4 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView4.model);
}
}];
}
-(void)changeAction:(UIButton*)sender{
[self.userView1 stopFloatAnimation];
[self.userView2 stopFloatAnimation];
[self.userView3 stopFloatAnimation];
[self.userView4 stopFloatAnimation];
self.fengcheImageView.alpha = 0;
self.fengcheImageView.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
self.changeBtn.alpha = 0;
self.fengcheImageView.alpha = 1;
self.userView1.centerX = self.bgImageView.centerX;
self.userView1.centerY = self.bgImageView.centerY;
self.userView2.centerX = self.bgImageView.centerX;
self.userView2.centerY = self.bgImageView.centerY;
self.userView3.centerX = self.bgImageView.centerX;
self.userView3.centerY = self.bgImageView.centerY;
self.userView4.centerX = self.bgImageView.centerX;
self.userView4.centerY = self.bgImageView.centerY;
self.userView1.alpha = 0;
self.userView2.alpha = 0;
self.userView3.alpha = 0;
self.userView4.alpha = 0;
} completion:^(BOOL finished) {
self.changeBtn.hidden = YES;
[self fengchezhuan];
}];
}
-(void)fengchezhuan{
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//旋转角度
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI];
//每次旋转的时间(单位秒)
rotationAnimation.duration = 0.2;
// rotationAnimation.repeatCount = 15;
rotationAnimation.delegate = self;
rotationAnimation.cumulative = YES;
rotationAnimation.removedOnCompletion = NO;
//重复旋转的次数如果你想要无数次那么设置成MAXFLOAT
rotationAnimation.repeatCount = 8;
[self.fengcheImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
self.changeBtn.alpha = 0;
self.changeBtn.hidden = NO;
self.fengcheImageView.hidden = YES;
[self configData];
[UIView animateWithDuration:0.3 animations:^{
self.changeBtn.alpha = 1;
self.userView1.frame = CGRectMake(self.bgImageView.left+40, self.bgImageView.top+28, 100, 100);
self.userView2.frame = CGRectMake(self.bgImageView.right-40-100, self.bgImageView.top+28, 100, 100);
self.userView3.frame = CGRectMake(self.bgImageView.left+40, self.bgImageView.bottom-55-100, 100, 100);
self.userView4.frame = CGRectMake(self.bgImageView.right-40-100, self.bgImageView.bottom-55-100, 100, 100);
self.userView1.alpha = 1;
self.userView2.alpha = 1;
self.userView3.alpha = 1;
self.userView4.alpha = 1;
} completion:^(BOOL finished) {
[self.userView1 startSmoothFloatAnimation];
[self.userView2 startSmoothFloatAnimation];
[self.userView3 startSmoothFloatAnimation];
[self.userView4 startSmoothFloatAnimation];
}];
}
-(void)setUsers:(NSArray *)users{
_users = users;
[self changeAction:self.changeBtn];
}
-(void)configData{
[self.randomArray removeAllObjects];
if (_users.count <= 4) {
[self.randomArray addObjectsFromArray:self.users];
}else{
NSArray *rArr = [self optimizedRandomFourNumbers];
for (NSNumber *number in rArr) {
[self.randomArray addObject:self.users[number.integerValue]];
}
}
for (int i = 0 ; i < self.randomArray.count;i++) {
QXUserHomeModel *md = self.randomArray[i];
QXExpansionAppStoreSubView *v = self.userViews[i];
v.model = md;
}
}
- (NSArray *)optimizedRandomFourNumbers {
NSMutableArray *allNumbers = [NSMutableArray arrayWithCapacity:self.users.count-1];
for (int i = 1; i < self.users.count; i++) {
[allNumbers addObject:@(i)];
}
NSMutableArray *result = [NSMutableArray arrayWithCapacity:4];
for (int i = 0; i < 4; i++) {
int remainingCount = (int)allNumbers.count;
int randomIndex = arc4random_uniform(remainingCount);
[result addObject:allNumbers[randomIndex]];
[allNumbers removeObjectAtIndex:randomIndex];
}
return result;
}
-(NSMutableArray *)randomArray{
if (!_randomArray) {
_randomArray = [NSMutableArray array];
}
return _randomArray;
}
-(NSMutableArray *)userViews{
if (!_userViews) {
_userViews = [NSMutableArray array];
}
return _userViews;
}
@end
@implementation QXExpansionAppStoreSubView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)setModel:(QXUserHomeModel *)model{
_model = model;
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
self.nameLabel.text = model.nickname;
UIImage *sexImage = [UIImage imageNamed:model.sex.intValue==1?@"user_sex_boy":@"user_sex_girl"];
self.sexImageView.image = sexImage;
}
-(void)initSubviews{
self.headerImageView = [[UIImageView alloc] init];
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.headerImageView addRoundedCornersWithRadius:35];
// self.headerImageView.backgroundColor = [UIColor brownColor];;
[self addSubview:self.headerImageView];
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.centerX.equalTo(self);
make.height.width.mas_offset(70);
}];
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.textColor = RGB16(0x333333);
self.nameLabel.font = [UIFont systemFontOfSize:14];
// self.nameLabel.text = @"张三";
[self addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.headerImageView.mas_bottom).offset(8);
make.centerX.equalTo(self);
make.height.mas_equalTo(20);
}];
self.sexImageView = [[UIImageView alloc] init];
[self addSubview:self.sexImageView];
[self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.right.equalTo(self.headerImageView);
make.height.width.mas_offset(16);
}];
}
- (void)startSmoothFloatAnimation {
[self animateFloatUp];
}
- (void)animateFloatUp {
CGFloat floatDistance = 10.0f;
CGFloat duration = 2.0f;
[UIView animateWithDuration:duration
delay:0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.transform = CGAffineTransformMakeTranslation(0, -floatDistance);
}
completion:^(BOOL finished) {
[self animateFloatDown];
}];
}
- (void)animateFloatDown {
CGFloat duration = 2.0f;
[UIView animateWithDuration:duration
delay:0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished) {
[self animateFloatUp];
}];
}
- (void)stopFloatAnimation {
[self.layer removeAllAnimations];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
@end