Files
featherVoice/QXLive/Dynamic(语圈)/View/QXExpansionAppStoreView.m
启星 c92b8eb910 1.1.2
2025-10-30 18:30:45 +08:00

644 lines
25 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)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;
@property (nonatomic,strong)NSMutableArray *userViews;
@property (nonatomic,strong)NSMutableArray *userViewCopys;
@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic, assign) CGFloat currentRotation;
@property (nonatomic, assign) CGFloat rotationSpeed;
@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.userView1.hidden = YES;
[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.userView2.hidden = YES;
[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.userView3.hidden = YES;
[self.centerBgView addSubview:self.userView3];
self.userView4 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView2.left, self.userView3.bottom+ScaleWidth(32), ScaleWidth(56), ScaleWidth(71))];
self.userView4.hidden = YES;
[self.centerBgView addSubview:self.userView4];
self.userView5 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView1.left, self.centerBgView.height-ScaleWidth(71), ScaleWidth(56), ScaleWidth(71))];
self.userView5.hidden = YES;
[self.centerBgView addSubview:self.userView5];
self.userView7 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(ScaleWidth(10), self.userView3.top, ScaleWidth(56), ScaleWidth(71))];
self.userView7.hidden = YES;
[self.centerBgView addSubview:self.userView7];
self.userView8 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(ScaleWidth(48), self.userView2.top, ScaleWidth(56), ScaleWidth(71))];
self.userView8.hidden = YES;
[self.centerBgView addSubview:self.userView8];
self.userView6 = [[QXExpansionAppStoreSubView alloc] initWithFrame:CGRectMake(self.userView8.left, self.userView4.top, ScaleWidth(56), ScaleWidth(71))];
self.userView6.hidden = YES;
[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.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;
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];
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];
}
- (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);
// 关键修复:头像反向旋转保持垂直
// 注意这里使用identity来重置transform然后应用反向旋转
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);
}
}
-(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;
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;
[UIView animateWithDuration:0.3 animations:^{
self.changeBtn.alpha = 0;
self.fengcheImageView.alpha = 1;
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;
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;
} 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.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;
} completion:^(BOOL finished) {
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;
}];
}
-(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];
QXExpansionAppStoreSubView *cv = self.userViewCopys[i];
v.model = md;
cv.model = [md copyModel];
}
}
- (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;
}
-(NSMutableArray *)userViewCopys{
if (!_userViewCopys) {
_userViewCopys = [NSMutableArray array];
}
return _userViewCopys;
}
@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.transform = CGAffineTransformRotate(self.transform, M_PI);
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"];
// [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];
// }
// }];
}
- (void)stopFloatAnimation {
[self.layer removeAllAnimations];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
@end