Files
mier_ios/SweetParty/主类/音悦新增/幸运礼物连击/YYLuckyCircleView.m
2025-08-11 10:43:19 +08:00

160 lines
4.6 KiB
Objective-C
Executable File
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.

//
// 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.0前两个是控制view的大小的
[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