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

468 lines
19 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)UIImageView *topCenterImageView;
@property (nonatomic,strong)UIImageView *moonImageView;
@property (nonatomic,strong)UIImageView *bottomImageView;
@property (nonatomic,strong)UIImageView *legImageView;
@property (nonatomic,strong)UIView *centerBgView;
@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)QXExpansionAppStoreSubView *userView5;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView6;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView7;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView8;
@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.topCenterImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exbpansion_word"]];
self.topCenterImageView.frame = CGRectMake((SCREEN_WIDTH-ScaleWidth(275))/2, 17, ScaleWidth(275), ScaleWidth(40));
self.topCenterImageView.contentMode = UIViewContentModeScaleToFill;
[self addSubview:self.topCenterImageView];
self.moonImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exbpansion_moon"]];
self.moonImageView.contentMode = UIViewContentModeScaleToFill;
self.moonImageView.frame = CGRectMake(self.topCenterImageView.right, 5, ScaleWidth(44), ScaleWidth(52));
[self addSubview:self.moonImageView];
self.bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exbpansion_bottom_bg"]];
self.bottomImageView.frame = CGRectMake(0, self.height-ScaleWidth(180), SCREEN_WIDTH, ScaleWidth(180));
self.bottomImageView.contentMode = UIViewContentModeScaleToFill;
[self addSubview:self.bottomImageView];
self.legImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exbpansion_bottom_leg"]];
self.legImageView.contentMode = UIViewContentModeScaleToFill;
self.legImageView.frame = CGRectMake((SCREEN_WIDTH-ScaleWidth(175))/2, self.bottomImageView.top-ScaleWidth(240-56), ScaleWidth(175), ScaleWidth(240));
[self insertSubview:self.legImageView belowSubview:self.bottomImageView];
self.centerBgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.legImageView.top-SCREEN_WIDTH/2, SCREEN_WIDTH, SCREEN_WIDTH)];
[self addSubview:self.centerBgView];
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exbpansion_center_bg"]];
self.bgImageView.frame = CGRectMake((SCREEN_WIDTH-ScaleWidth(300))/2, (SCREEN_WIDTH-ScaleWidth(300))/2,ScaleWidth(300), ScaleWidth(300));
[self.centerBgView addSubview:self.bgImageView];
// [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.height.width.mas_equalTo(375);
// make.centerX.centerY.equalTo(self);
// }];
self.fengcheImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fengche"]];
self.fengcheImageView.hidden = YES;
self.fengcheImageView.frame = CGRectMake((self.centerBgView.width-ScaleWidth(60))/2, (self.centerBgView.top-ScaleWidth(60))/2, ScaleWidth(60), ScaleWidth(60));
[self.fengcheImageView addRoundedCornersWithRadius:ScaleWidth(30)];
self.fengcheImageView.layer.borderWidth = 5;
self.fengcheImageView.layer.borderColor = UIColor.whiteColor.CGColor;
self.fengcheImageView.centerX = self.centerBgView.centerX;
self.fengcheImageView.centerY = self.centerBgView.centerY;
[self addSubview:self.fengcheImageView];
self.changeBtn = [[UIButton alloc] init];
self.changeBtn.frame = self.fengcheImageView.frame;
self.changeBtn.backgroundColor = QXConfig.themeColor;
[self.changeBtn addRoundedCornersWithRadius:ScaleWidth(30)];
[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(0xffffff) 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.centerBgView.width-ScaleWidth(56))/2, 0, ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView1];
self.userView2 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView1.right+ScaleWidth(54), self.userView1.top+ScaleWidth(45), ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView2];
self.userView3 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-ScaleWidth(66), (self.centerBgView.height-ScaleWidth(71))/2, ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView3];
self.userView4 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView2.left, self.userView3.bottom+ScaleWidth(32), ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView4];
self.userView5 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView1.left, self.centerBgView.height-ScaleWidth(71), ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView5];
self.userView7 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(ScaleWidth(10), self.userView3.top, ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView7];
self.userView8 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(ScaleWidth(48), self.userView2.top, ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView8];
self.userView6 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView8.left, self.userView4.top, ScaleWidth(56), ScaleWidth(71))];
[self.centerBgView addSubview:self.userView6];
[self.userViews addObject:self.userView1];
[self.userViews addObject:self.userView2];
[self.userViews addObject:self.userView3];
[self.userViews addObject:self.userView4];
[self.userViews addObject:self.userView5];
[self.userViews addObject:self.userView6];
[self.userViews addObject:self.userView7];
[self.userViews addObject:self.userView8];
self.userView1.alpha = 0;
self.userView2.alpha = 0;
self.userView3.alpha = 0;
self.userView4.alpha = 0;
self.userView5.alpha = 0;
self.userView6.alpha = 0;
self.userView7.alpha = 0;
self.userView8.alpha = 0;
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);
}
}];
[self.userView5 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView5.model);
}
}];
[self.userView6 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView6.model);
}
}];
[self.userView7 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView7.model);
}
}];
[self.userView8 addTapBlock:^(id _Nonnull obj) {
if (weakSelf.userBlock) {
weakSelf.userBlock(weakSelf.userView8.model);
}
}];
[self startAnimate];
[self.userView1 startSmoothFloatAnimation];
[self.userView2 startSmoothFloatAnimation];
[self.userView3 startSmoothFloatAnimation];
[self.userView4 startSmoothFloatAnimation];
[self.userView5 startSmoothFloatAnimation];
[self.userView6 startSmoothFloatAnimation];
[self.userView7 startSmoothFloatAnimation];
[self.userView8 startSmoothFloatAnimation];
}
-(void)startAnimate{
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//旋转角度
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI];
//每次旋转的时间(单位秒)
rotationAnimation.duration = 15;
rotationAnimation.cumulative = YES;
rotationAnimation.removedOnCompletion = NO;
//重复旋转的次数如果你想要无数次那么设置成MAXFLOAT
rotationAnimation.repeatCount = MAXFLOAT;
[self.centerBgView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
-(void)changeAction:(UIButton*)sender{
// [self.userView1 stopFloatAnimation];
// [self.userView2 stopFloatAnimation];
// [self.userView3 stopFloatAnimation];
// [self.userView4 stopFloatAnimation];
// [self.userView5 stopFloatAnimation];
// [self.userView6 stopFloatAnimation];
// [self.userView7 stopFloatAnimation];
// [self.userView8 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.userView5.centerX = self.bgImageView.centerX;
self.userView5.centerY = self.bgImageView.centerY;
self.userView6.centerX = self.bgImageView.centerX;
self.userView6.centerY = self.bgImageView.centerY;
self.userView7.centerX = self.bgImageView.centerX;
self.userView7.centerY = self.bgImageView.centerY;
self.userView8.centerX = self.bgImageView.centerX;
self.userView8.centerY = self.bgImageView.centerY;
self.userView1.alpha = 0;
self.userView2.alpha = 0;
self.userView3.alpha = 0;
self.userView4.alpha = 0;
self.userView5.alpha = 0;
self.userView6.alpha = 0;
self.userView7.alpha = 0;
self.userView8.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;
dispatch_async(dispatch_get_main_queue(), ^{
[self configData];
});
[UIView animateWithDuration:0.3 animations:^{
self.changeBtn.alpha = 1;
self.userView1.frame = CGRectMake((self.centerBgView.width-ScaleWidth(56))/2, 0, ScaleWidth(56), ScaleWidth(71));
self.userView2.frame = CGRectMake(self.userView1.right+ScaleWidth(54), self.userView1.top+ScaleWidth(45), ScaleWidth(56), ScaleWidth(71));
self.userView3.frame = CGRectMake(SCREEN_WIDTH-ScaleWidth(66), (self.centerBgView.height-ScaleWidth(71))/2, ScaleWidth(56), ScaleWidth(71));
self.userView4.frame = CGRectMake(self.userView2.left, self.userView3.bottom+ScaleWidth(32), ScaleWidth(56), ScaleWidth(71));
self.userView5.frame = CGRectMake(self.userView1.left, self.centerBgView.height-ScaleWidth(71), ScaleWidth(56), ScaleWidth(71));
self.userView7.frame = CGRectMake(ScaleWidth(10), self.userView3.top, ScaleWidth(56), ScaleWidth(71));
self.userView8.frame = CGRectMake(ScaleWidth(48), self.userView2.top, ScaleWidth(56), ScaleWidth(71));
self.userView6.frame = CGRectMake(self.userView8.left, self.userView4.top, ScaleWidth(56), ScaleWidth(71));
self.userView1.alpha = 1;
self.userView2.alpha = 1;
self.userView3.alpha = 1;
self.userView4.alpha = 1;
self.userView5.alpha = 1;
self.userView6.alpha = 1;
self.userView7.alpha = 1;
self.userView8.alpha = 1;
} completion:^(BOOL finished) {
}];
}
-(void)setUsers:(NSArray *)users{
_users = users;
[self changeAction:self.changeBtn];
}
-(void)configData{
[self.randomArray removeAllObjects];
if (_users.count <= 8) {
[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:8];
for (int i = 0; i < 8; 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;
self.nameBgView.hidden = NO;
}
-(void)initSubviews{
self.headerImageView = [[UIImageView alloc] init];
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.headerImageView addRoundedCornersWithRadius:self.width/2];
[self addSubview:self.headerImageView];
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self);
make.height.width.mas_offset(self.width);
}];
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.textColor = RGB16(0xe5e5e5);
self.nameLabel.font = [UIFont systemFontOfSize:9];
[self addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.headerImageView.mas_bottom).offset(2);
make.centerX.equalTo(self);
make.height.mas_equalTo(ScaleWidth(15));
}];
self.nameBgView = [[UIView alloc] init];
self.nameBgView.hidden = YES;
self.nameBgView.backgroundColor = RGB16A(0x000000, 0.58);
[self.nameBgView addRoundedCornersWithRadius:ScaleWidth(15)/2];
[self insertSubview:self.nameBgView belowSubview:self.nameLabel];
[self.nameBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self.nameLabel);
make.left.mas_equalTo(-8);
make.right.mas_equalTo(8);
}];
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];
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//旋转角度
rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI];
//每次旋转的时间(单位秒)
rotationAnimation.duration = 15;
rotationAnimation.cumulative = YES;
rotationAnimation.removedOnCompletion = NO;
//重复旋转的次数如果你想要无数次那么设置成MAXFLOAT
rotationAnimation.repeatCount = MAXFLOAT;
[self.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
- (void)stopFloatAnimation {
[self.layer removeAllAnimations];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
@end