Files
featherVoice/QXLive/Dynamic(语圈)/View/QXExpansionAppStoreView.m

644 lines
25 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXExpansionAppStoreView.m
// QXLive
//
// Created by on 2025/7/31.
//
#import "QXExpansionAppStoreView.h"
#import "CKShimmerLabel.h"
@interface QXExpansionAppStoreView()<CAAnimationDelegate>
2025-10-30 00:45:15 +08:00
@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;
2025-08-08 10:49:36 +08:00
@property (nonatomic,strong)UIImageView *bgImageView;
2025-10-30 00:45:15 +08:00
2025-08-08 10:49:36 +08:00
@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;
2025-10-30 00:45:15 +08:00
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView5;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView6;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView7;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userView8;
2025-10-30 18:30:45 +08:00
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy1;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy2;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy3;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy4;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy5;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy6;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy7;
@property (nonatomic,strong)QXExpansionAppStoreSubView *userViewCopy8;
2025-08-08 10:49:36 +08:00
@property (nonatomic,strong)NSMutableArray *userViews;
2025-10-30 18:30:45 +08:00
@property (nonatomic,strong)NSMutableArray *userViewCopys;
@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic, assign) CGFloat currentRotation;
@property (nonatomic, assign) CGFloat rotationSpeed;
2025-08-08 10:49:36 +08:00
@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{
2025-10-30 00:45:15 +08:00
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];
2025-08-08 10:49:36 +08:00
2025-10-30 00:45:15 +08:00
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];
2025-08-08 10:49:36 +08:00
// [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.height.width.mas_equalTo(375);
// make.centerX.centerY.equalTo(self);
// }];
2025-10-30 00:45:15 +08:00
2025-08-08 10:49:36 +08:00
self.fengcheImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fengche"]];
self.fengcheImageView.hidden = YES;
2025-10-30 00:45:15 +08:00
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)];
2025-08-08 10:49:36 +08:00
self.fengcheImageView.layer.borderWidth = 5;
self.fengcheImageView.layer.borderColor = UIColor.whiteColor.CGColor;
2025-10-30 00:45:15 +08:00
self.fengcheImageView.centerX = self.centerBgView.centerX;
self.fengcheImageView.centerY = self.centerBgView.centerY;
2025-08-08 10:49:36 +08:00
[self addSubview:self.fengcheImageView];
2025-10-30 00:45:15 +08:00
2025-08-08 10:49:36 +08:00
self.changeBtn = [[UIButton alloc] init];
self.changeBtn.frame = self.fengcheImageView.frame;
self.changeBtn.backgroundColor = QXConfig.themeColor;
2025-10-30 00:45:15 +08:00
[self.changeBtn addRoundedCornersWithRadius:ScaleWidth(30)];
[self.changeBtn setTitle:@"换" forState:(UIControlStateNormal)];
2025-08-08 10:49:36 +08:00
self.changeBtn.layer.borderWidth = 5;
self.changeBtn.layer.borderColor = UIColor.whiteColor.CGColor;
self.changeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
2025-10-30 00:45:15 +08:00
[self.changeBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
2025-08-08 10:49:36 +08:00
[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);
// }];
2025-10-30 00:45:15 +08:00
self.userView1 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake((self.centerBgView.width-ScaleWidth(56))/2, 0, ScaleWidth(56), ScaleWidth(71))];
2025-10-30 18:30:45 +08:00
self.userView1.hidden = YES;
2025-10-30 00:45:15 +08:00
[self.centerBgView addSubview:self.userView1];
2025-08-08 10:49:36 +08:00
2025-10-30 00:45:15 +08:00
self.userView2 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView1.right+ScaleWidth(54), self.userView1.top+ScaleWidth(45), ScaleWidth(56), ScaleWidth(71))];
2025-10-30 18:30:45 +08:00
self.userView2.hidden = YES;
2025-10-30 00:45:15 +08:00
[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))];
2025-10-30 18:30:45 +08:00
self.userView3.hidden = YES;
2025-10-30 00:45:15 +08:00
[self.centerBgView addSubview:self.userView3];
self.userView4 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView2.left, self.userView3.bottom+ScaleWidth(32), ScaleWidth(56), ScaleWidth(71))];
2025-10-30 18:30:45 +08:00
self.userView4.hidden = YES;
2025-10-30 00:45:15 +08:00
[self.centerBgView addSubview:self.userView4];
self.userView5 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView1.left, self.centerBgView.height-ScaleWidth(71), ScaleWidth(56), ScaleWidth(71))];
2025-10-30 18:30:45 +08:00
self.userView5.hidden = YES;
2025-10-30 00:45:15 +08:00
[self.centerBgView addSubview:self.userView5];
self.userView7 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(ScaleWidth(10), self.userView3.top, ScaleWidth(56), ScaleWidth(71))];
2025-10-30 18:30:45 +08:00
self.userView7.hidden = YES;
2025-10-30 00:45:15 +08:00
[self.centerBgView addSubview:self.userView7];
self.userView8 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(ScaleWidth(48), self.userView2.top, ScaleWidth(56), ScaleWidth(71))];
2025-10-30 18:30:45 +08:00
self.userView8.hidden = YES;
2025-10-30 00:45:15 +08:00
[self.centerBgView addSubview:self.userView8];
self.userView6 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView8.left, self.userView4.top, ScaleWidth(56), ScaleWidth(71))];
2025-10-30 18:30:45 +08:00
self.userView6.hidden = YES;
2025-10-30 00:45:15 +08:00
[self.centerBgView addSubview:self.userView6];
2025-08-08 10:49:36 +08:00
[self.userViews addObject:self.userView1];
[self.userViews addObject:self.userView2];
[self.userViews addObject:self.userView3];
[self.userViews addObject:self.userView4];
2025-10-30 00:45:15 +08:00
[self.userViews addObject:self.userView5];
[self.userViews addObject:self.userView6];
[self.userViews addObject:self.userView7];
[self.userViews addObject:self.userView8];
2025-10-30 18:30:45 +08:00
self.userViewCopy1 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView1.frame];
self.userViewCopy1.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy1];
self.userViewCopy2 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView2.frame];
self.userViewCopy2.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy2];
self.userViewCopy3 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView3.frame];
self.userViewCopy3.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy3];
self.userViewCopy4 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView4.frame];
self.userViewCopy4.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy4];
self.userViewCopy5 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView5.frame];
self.userViewCopy5.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy5];
self.userViewCopy7 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView7.frame];
self.userViewCopy7.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy7];
self.userViewCopy8 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView8.frame];
self.userViewCopy8.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy8];
self.userViewCopy6 = [[QXExpansionAppStoreSubView alloc] initWithFrame:self.userView6.frame];
self.userViewCopy6.hidden = YES;
[self.centerBgView addSubview:self.userViewCopy6];
[self.userViewCopys addObject:self.userViewCopy1];
[self.userViewCopys addObject:self.userViewCopy2];
[self.userViewCopys addObject:self.userViewCopy3];
[self.userViewCopys addObject:self.userViewCopy4];
[self.userViewCopys addObject:self.userViewCopy5];
[self.userViewCopys addObject:self.userViewCopy6];
[self.userViewCopys addObject:self.userViewCopy7];
[self.userViewCopys addObject:self.userViewCopy8];
self.userViewCopy1.alpha = 0;
self.userViewCopy2.alpha = 0;
self.userViewCopy3.alpha = 0;
self.userViewCopy4.alpha = 0;
self.userViewCopy5.alpha = 0;
self.userViewCopy6.alpha = 0;
self.userViewCopy7.alpha = 0;
self.userViewCopy8.alpha = 0;
2025-08-08 10:49:36 +08:00
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);
}
}];
2025-10-30 00:45:15 +08:00
[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);
}
}];
2025-10-30 18:30:45 +08:00
// [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];
self.rotationSpeed = (M_PI * 2) / (30.0 * 60.0); // 30
[self startWheelRotation];
}
- (void)startWheelRotation {
self.currentRotation = 0;
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateWheelRotation)];
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
2025-10-30 00:45:15 +08:00
}
2025-10-30 18:30:45 +08:00
- (void)updateWheelRotation {
//
self.currentRotation += self.rotationSpeed;
if (self.currentRotation >= M_PI * 2) {
self.currentRotation -= M_PI * 2;
}
// 1使CGAffineTransform
[self updateRotationWithCGAffineTransform];
// 2使CATransform3D
// [self updateRotationWithCATransform3D];
//
// [self updateDebugInfo];
}
// 1使CGAffineTransform
- (void)updateRotationWithCGAffineTransform {
//
self.centerBgView.transform = CGAffineTransformMakeRotation(self.currentRotation);
//
// 使identitytransform
for (QXExpansionAppStoreSubView *avatarView in self.userViews) {
// transform
avatarView.transform = CGAffineTransformIdentity;
avatarView.transform = CGAffineTransformMakeRotation(-self.currentRotation);
}
for (QXExpansionAppStoreSubView *avatarView in self.userViewCopys) {
// transform
avatarView.transform = CGAffineTransformIdentity;
avatarView.transform = CGAffineTransformMakeRotation(-self.currentRotation);
}
}
2025-10-30 00:45:15 +08:00
-(void)startAnimate{
2025-10-30 18:30:45 +08:00
// 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"];
2025-08-08 10:49:36 +08:00
}
2025-10-30 00:45:15 +08:00
2025-08-08 10:49:36 +08:00
-(void)changeAction:(UIButton*)sender{
2025-10-30 00:45:15 +08:00
// [self.userView1 stopFloatAnimation];
// [self.userView2 stopFloatAnimation];
// [self.userView3 stopFloatAnimation];
// [self.userView4 stopFloatAnimation];
// [self.userView5 stopFloatAnimation];
// [self.userView6 stopFloatAnimation];
// [self.userView7 stopFloatAnimation];
// [self.userView8 stopFloatAnimation];
2025-08-08 10:49:36 +08:00
self.fengcheImageView.alpha = 0;
self.fengcheImageView.hidden = NO;
2025-10-30 18:30:45 +08:00
self.userViewCopy1.hidden = NO;
self.userViewCopy2.hidden = NO;
self.userViewCopy3.hidden = NO;
self.userViewCopy4.hidden = NO;
self.userViewCopy5.hidden = NO;
self.userViewCopy6.hidden = NO;
self.userViewCopy7.hidden = NO;
self.userViewCopy8.hidden = NO;
self.userView1.hidden = YES;
self.userView2.hidden = YES;
self.userView3.hidden = YES;
self.userView4.hidden = YES;
self.userView5.hidden = YES;
self.userView6.hidden = YES;
self.userView7.hidden = YES;
self.userView8.hidden = YES;
2025-08-08 10:49:36 +08:00
[UIView animateWithDuration:0.3 animations:^{
self.changeBtn.alpha = 0;
self.fengcheImageView.alpha = 1;
2025-10-30 18:30:45 +08:00
self.userViewCopy1.centerX = self.bgImageView.centerX;
self.userViewCopy1.centerY = self.bgImageView.centerY;
self.userViewCopy2.centerX = self.bgImageView.centerX;
self.userViewCopy2.centerY = self.bgImageView.centerY;
self.userViewCopy3.centerX = self.bgImageView.centerX;
self.userViewCopy3.centerY = self.bgImageView.centerY;
self.userViewCopy4.centerX = self.bgImageView.centerX;
self.userViewCopy4.centerY = self.bgImageView.centerY;
2025-08-08 10:49:36 +08:00
2025-10-30 18:30:45 +08:00
self.userViewCopy5.centerX = self.bgImageView.centerX;
self.userViewCopy5.centerY = self.bgImageView.centerY;
self.userViewCopy6.centerX = self.bgImageView.centerX;
self.userViewCopy6.centerY = self.bgImageView.centerY;
self.userViewCopy7.centerX = self.bgImageView.centerX;
self.userViewCopy7.centerY = self.bgImageView.centerY;
self.userViewCopy8.centerX = self.bgImageView.centerX;
self.userViewCopy8.centerY = self.bgImageView.centerY;
self.userViewCopy1.alpha = 0;
self.userViewCopy2.alpha = 0;
self.userViewCopy3.alpha = 0;
self.userViewCopy4.alpha = 0;
self.userViewCopy5.alpha = 0;
self.userViewCopy6.alpha = 0;
self.userViewCopy7.alpha = 0;
self.userViewCopy8.alpha = 0;
2025-08-08 10:49:36 +08:00
} 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;
2025-10-30 18:30:45 +08:00
[self configData];
2025-08-08 10:49:36 +08:00
[UIView animateWithDuration:0.3 animations:^{
self.changeBtn.alpha = 1;
2025-10-30 18:30:45 +08:00
self.userViewCopy1.frame = self.userView1.frame;
self.userViewCopy2.frame = self.userView2.frame;
self.userViewCopy3.frame = self.userView3.frame;
self.userViewCopy4.frame = self.userView4.frame;
self.userViewCopy5.frame = self.userView5.frame;
self.userViewCopy6.frame = self.userView6.frame;
self.userViewCopy7.frame = self.userView7.frame;
self.userViewCopy8.frame = self.userView8.frame;
self.userViewCopy1.alpha = 1;
self.userViewCopy2.alpha = 1;
self.userViewCopy3.alpha = 1;
self.userViewCopy4.alpha = 1;
self.userViewCopy5.alpha = 1;
self.userViewCopy6.alpha = 1;
self.userViewCopy7.alpha = 1;
self.userViewCopy8.alpha = 1;
2025-10-30 00:45:15 +08:00
2025-08-08 10:49:36 +08:00
} completion:^(BOOL finished) {
2025-10-30 18:30:45 +08:00
self.userViewCopy1.hidden = YES;
self.userViewCopy2.hidden = YES;
self.userViewCopy3.hidden = YES;
self.userViewCopy4.hidden = YES;
self.userViewCopy5.hidden = YES;
self.userViewCopy6.hidden = YES;
self.userViewCopy7.hidden = YES;
self.userViewCopy8.hidden = YES;
self.userView1.hidden = NO;
self.userView2.hidden = NO;
self.userView3.hidden = NO;
self.userView4.hidden = NO;
self.userView5.hidden = NO;
self.userView6.hidden = NO;
self.userView7.hidden = NO;
self.userView8.hidden = NO;
2025-08-08 10:49:36 +08:00
}];
}
-(void)setUsers:(NSArray *)users{
_users = users;
[self changeAction:self.changeBtn];
}
-(void)configData{
[self.randomArray removeAllObjects];
2025-10-30 00:45:15 +08:00
if (_users.count <= 8) {
2025-08-08 10:49:36 +08:00
[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];
2025-10-30 18:30:45 +08:00
QXExpansionAppStoreSubView *cv = self.userViewCopys[i];
2025-08-08 10:49:36 +08:00
v.model = md;
2025-10-30 18:30:45 +08:00
cv.model = [md copyModel];
2025-08-08 10:49:36 +08:00
}
}
- (NSArray *)optimizedRandomFourNumbers {
NSMutableArray *allNumbers = [NSMutableArray arrayWithCapacity:self.users.count-1];
for (int i = 1; i < self.users.count; i++) {
[allNumbers addObject:@(i)];
}
2025-10-30 00:45:15 +08:00
NSMutableArray *result = [NSMutableArray arrayWithCapacity:8];
for (int i = 0; i < 8; i++) {
2025-08-08 10:49:36 +08:00
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;
}
2025-10-30 18:30:45 +08:00
-(NSMutableArray *)userViewCopys{
if (!_userViewCopys) {
_userViewCopys = [NSMutableArray array];
}
return _userViewCopys;
}
2025-08-08 10:49:36 +08:00
@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;
2025-10-30 00:45:15 +08:00
self.nameBgView.hidden = NO;
2025-08-08 10:49:36 +08:00
}
-(void)initSubviews{
2025-10-30 18:30:45 +08:00
self.transform = CGAffineTransformRotate(self.transform, M_PI);
2025-08-08 10:49:36 +08:00
self.headerImageView = [[UIImageView alloc] init];
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
2025-10-30 00:45:15 +08:00
[self.headerImageView addRoundedCornersWithRadius:self.width/2];
2025-08-08 10:49:36 +08:00
[self addSubview:self.headerImageView];
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2025-10-30 00:45:15 +08:00
make.centerX.equalTo(self);
make.top.equalTo(self);
make.height.width.mas_offset(self.width);
2025-08-08 10:49:36 +08:00
}];
2025-10-30 00:45:15 +08:00
2025-08-08 10:49:36 +08:00
self.nameLabel = [[UILabel alloc] init];
2025-10-30 00:45:15 +08:00
self.nameLabel.textColor = RGB16(0xe5e5e5);
self.nameLabel.font = [UIFont systemFontOfSize:9];
2025-08-08 10:49:36 +08:00
[self addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
2025-10-30 00:45:15 +08:00
make.top.equalTo(self.headerImageView.mas_bottom).offset(2);
2025-08-08 10:49:36 +08:00
make.centerX.equalTo(self);
2025-10-30 00:45:15 +08:00
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);
2025-08-08 10:49:36 +08:00
}];
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);
}];
}
2025-10-30 18:30:45 +08:00
2025-08-08 10:49:36 +08:00
- (void)startSmoothFloatAnimation {
2025-10-30 18:30:45 +08:00
2025-10-30 00:45:15 +08:00
// [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"];
2025-10-30 18:30:45 +08:00
// [UIView animateWithDuration:15.0
// delay:0.0
// options:UIViewAnimationOptionCurveLinear|UIViewKeyframeAnimationOptionAllowUserInteraction
// animations:^{
// self.transform = CGAffineTransformRotate(self.transform, 2*M_PI);
// }
// completion:^(BOOL finished) {
// if (finished) {
// //
// [self startSmoothFloatAnimation];
// }
// }];
2025-08-08 10:49:36 +08:00
}
- (void)stopFloatAnimation {
[self.layer removeAllAnimations];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
@end