Files
yuyin_ios/SweetParty/主类/音悦新增/幸运礼物连击/YYLuckyCircleView.m

160 lines
4.6 KiB
Mathematica
Raw Normal View History

2025-08-08 11:05:33 +08:00
//
// YYLuckyCircleView.m
// YaYin
//
// Created by bj_szd on 2023/12/2.
// Copyright © 2023 YaYin. All rights reserved.
//
#import "YYLuckyCircleView.h"
#import "ZYCircleProgressView.h"
#import "ZWTimer.h"
@interface YYLuckyCircleView () <ZWTimerDelegate>
{
CAKeyframeAnimation* animation;
}
@property (nonatomic, strong) ZYCircleProgressView *progressView;
@property (nonatomic, strong) ZWTimer *timer;
@property (nonatomic, assign) float leftSecond;
@property (nonatomic, strong) UIImageView *giftImgV;
@property (nonatomic, strong) UILabel *balanceLab;
@end
@implementation YYLuckyCircleView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self createUI];
}
return self;
}
- (void)createUI {
// self.backgroundColor = kBlackColor;
WEAK_SELF
[self dg_Tapped:^{
[weakSelf onReSend];
}];
self.giftImgV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 56, 56)];
self.giftImgV.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:self.giftImgV];
[self shakeToShow:self.giftImgV];
self.balanceLab = [ControlCreator createLabel:self rect:CGRectZero text:@"" font:YBBoldFont(12) color:HEXCOLOR(0xFFE928) backguoundColor:nil align:NSTextAlignmentLeft lines:1];
[self.balanceLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(0);
make.bottom.equalTo(self.mas_top).offset(-2);
}];
}
- (void)setImgStr:(NSString *)imgStr {
_imgStr = imgStr;
[self.giftImgV sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:kDefaultUserIcon];
}
- (void)setParamsDict:(NSDictionary *)paramsDict {
_paramsDict = paramsDict;
[self onStartAnimate];
}
- (void)setMoneyStr:(NSString *)moneyStr {
_moneyStr = moneyStr;
self.balanceLab.text = [NSString stringWithFormat:@"余额:%ld", [moneyStr integerValue]];
}
- (void)onReSend {
[RCMicHTTP postWithURLString:@"/api/gift/send_gift" parameters:self.paramsDict response:^(RCMicHTTPResult *result) {
if (result.success) {
if (result.errorCode == 200) {
// [HelpPageDefine showMessage:result.message];
[self onStartAnimate];
self.balanceLab.text = [NSString stringWithFormat:@"余额:%ld", [result.content safeIntForKey:@"integral"]];
//
NSArray *arr = [result.content safeArrayForKey:@"data"];
for (NSDictionary *dict in arr) {
//
self.viewModel.receivedGiftTuopan? self.viewModel.receivedGiftTuopan(dict) : nil;
}
}else if (result.errorCode == 302) {
//访
}else {
[SVProgressHUD showInfoWithStatus:result.message];
}
}else {
[SVProgressHUD showInfoWithStatus:@"网络错误"];
}
}];
}
- (void)onStartAnimate {
if (self.progressView) {
[self.progressView removeFromSuperview];
self.progressView = nil;
}
ZYCircleProgressView *progressView = [[ZYCircleProgressView alloc] initWithFrame:CGRectMake(0, 0, 66, 66)];
progressView.progress = 0.0;
[self insertSubview:progressView atIndex:0];
self.progressView = progressView;
self.leftSecond = 0;
[self.timer startGCDTimer:0.01 delegate:self];
}
- (void)onTimerFired:(ZWTimer *)timer {
self.leftSecond += 0.01;
self.progressView.progress = self.leftSecond*0.143;
// NSLog(@"转圈进度---%.2f", self.progressView.progress);
if (self.leftSecond >= 7) {
[self.timer stopTimer];
[self removeFromSuperview];
}
}
- (ZWTimer *)timer {
if (!_timer) {
_timer = [[ZWTimer alloc] init];
}
return _timer;
}
/** */
- (void) shakeToShow:(UIView*)aView
{
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 1.5;//
animation.repeatCount = 100000;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)]];
// 1.0view
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)]];
animation.values = values;
[aView.layer addAnimation:animation forKey:@"iconAnimation"];
}
@end