826 lines
34 KiB
Mathematica
826 lines
34 KiB
Mathematica
|
|
//
|
|||
|
|
// QXSkyPraizeView.m
|
|||
|
|
// QXLive
|
|||
|
|
//
|
|||
|
|
// Created by 启星 on 2025/8/16.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#import "QXSkyPraizeView.h"
|
|||
|
|
#import "UIButton+QX.h"
|
|||
|
|
#import <AVFoundation/AVFoundation.h>
|
|||
|
|
#import "QXSkyPraizeRuleView.h"
|
|||
|
|
#import "QXSkyPraizePoolView.h"
|
|||
|
|
#import "QXSkyPraizeRecordView.h"
|
|||
|
|
#import "QXDrawGiftCenterView.h"
|
|||
|
|
#import "QXDiamondViewController.h"
|
|||
|
|
|
|||
|
|
/// 共有12个礼物
|
|||
|
|
static NSInteger giftMaxCount = 12;
|
|||
|
|
/// 最少转2圈
|
|||
|
|
static NSInteger minRoundCount = 6;
|
|||
|
|
/// 距离4个的时候放慢
|
|||
|
|
static NSInteger toSlowCount = 4;
|
|||
|
|
|
|||
|
|
@interface QXSkyPraizeView()<UIGestureRecognizerDelegate>
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// 目标下标
|
|||
|
|
@property (nonatomic,assign)NSInteger targetIndex;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)NSMutableArray* targetArrayIndex;
|
|||
|
|
@property (nonatomic,strong)NSMutableArray* finishTargetArrayIndex;
|
|||
|
|
/// 当前转动到第几个下标
|
|||
|
|
@property (nonatomic,assign)NSInteger currentIndex;
|
|||
|
|
/// 转动了多少次
|
|||
|
|
@property (nonatomic,assign)NSInteger roundCount;
|
|||
|
|
/// 延时
|
|||
|
|
@property (nonatomic,assign)double delayTime;
|
|||
|
|
///// 22 抽一次 33 抽十次 44 抽 100次
|
|||
|
|
@property (nonatomic,assign)QXSkyDrawBtnType startType;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)QXSkyPraizeSubView *currentGiftView;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)UIView *bgView;
|
|||
|
|
@property (nonatomic,strong)UIImageView *bgImageView;
|
|||
|
|
/// 奖池
|
|||
|
|
@property (nonatomic,strong)UIButton *poolBtn;
|
|||
|
|
/// 规则
|
|||
|
|
@property (nonatomic,strong)UIButton *ruleBtn;
|
|||
|
|
/// 记录
|
|||
|
|
@property (nonatomic,strong)UIButton *recordBtn;
|
|||
|
|
|
|||
|
|
/// 音效
|
|||
|
|
@property (nonatomic,strong)UIButton *soundBtn;
|
|||
|
|
/// 特效
|
|||
|
|
@property (nonatomic,strong)UIButton *specialBtn;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)NSMutableArray *allViewsArray;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)dispatch_source_t fastTimer;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)AVPlayer* player;
|
|||
|
|
|
|||
|
|
/// 金币
|
|||
|
|
@property (nonatomic,strong)UIView* coinView;
|
|||
|
|
@property (nonatomic,strong)UIButton* coinBtn;
|
|||
|
|
@property (nonatomic,strong)UIButton* exchangeBtn;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)QXSkyDrawBtn *oneBtn;
|
|||
|
|
@property (nonatomic,strong)QXSkyDrawBtn *tenBtn;
|
|||
|
|
@property (nonatomic,strong)QXSkyDrawBtn *hundredBtn;
|
|||
|
|
@property (nonatomic,strong)QXDrawGiftResultModel *drawResultModel;
|
|||
|
|
/// 是否正在抽奖
|
|||
|
|
@property (nonatomic,assign)BOOL isDrawing;
|
|||
|
|
/// 是否开启音效
|
|||
|
|
@property (nonatomic,assign)BOOL isOpenSound;
|
|||
|
|
/// 是否开启特效
|
|||
|
|
@property (nonatomic,assign)BOOL isOpenSpecial;
|
|||
|
|
/// 规则视图
|
|||
|
|
@property (nonatomic,strong)QXSkyPraizeRuleView *ruleView;
|
|||
|
|
/// 奖池视图
|
|||
|
|
@property (nonatomic,strong)QXSkyPraizePoolView *poolView;
|
|||
|
|
/// 记录
|
|||
|
|
@property (nonatomic,strong)QXSkyPraizeRecordView *recordView;
|
|||
|
|
|
|||
|
|
@property (nonatomic,strong)QXDrawGiftCenterView * centerView;
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
@implementation QXSkyPraizeView
|
|||
|
|
|
|||
|
|
- (instancetype)init
|
|||
|
|
{
|
|||
|
|
self = [super init];
|
|||
|
|
if (self) {
|
|||
|
|
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|||
|
|
[self initSubviews];
|
|||
|
|
}
|
|||
|
|
return self;
|
|||
|
|
}
|
|||
|
|
-(void)initSubviews{
|
|||
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
|||
|
|
tap.delegate = self;
|
|||
|
|
[self addGestureRecognizer:tap];
|
|||
|
|
self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
|
|||
|
|
|
|||
|
|
self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(663))];
|
|||
|
|
[self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
|||
|
|
[self addSubview:self.bgView];
|
|||
|
|
|
|||
|
|
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"active_sky_raize_bg"]];
|
|||
|
|
self.bgImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(663));
|
|||
|
|
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
|
|||
|
|
[self.bgView addSubview:self.bgImageView];
|
|||
|
|
|
|||
|
|
self.poolBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, ScaleWidth(48), ScaleWidth(48), ScaleWidth(24))];
|
|||
|
|
[self.poolBtn setBackgroundImage:[UIImage imageNamed:@"sky_right_bg"] forState:(UIControlStateNormal)];
|
|||
|
|
[self.poolBtn setTitle:@"奖池" forState:(UIControlStateNormal)];
|
|||
|
|
[self.poolBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|||
|
|
self.poolBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|||
|
|
[self.poolBtn addTarget:self action:@selector(poolAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.bgView addSubview:self.poolBtn];
|
|||
|
|
|
|||
|
|
self.ruleBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-ScaleWidth(48), self.poolBtn.top, ScaleWidth(48), ScaleWidth(24))];
|
|||
|
|
[self.ruleBtn setBackgroundImage:[UIImage imageNamed:@"sky_left_bg"] forState:(UIControlStateNormal)];
|
|||
|
|
[self.ruleBtn setTitle:@"规则" forState:(UIControlStateNormal)];
|
|||
|
|
[self.ruleBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|||
|
|
self.ruleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|||
|
|
[self.ruleBtn addTarget:self action:@selector(ruleAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.bgView addSubview:self.ruleBtn];
|
|||
|
|
|
|||
|
|
self.recordBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.ruleBtn.left, self.ruleBtn.bottom+12, ScaleWidth(48), ScaleWidth(24))];
|
|||
|
|
[self.recordBtn setBackgroundImage:[UIImage imageNamed:@"sky_left_bg"] forState:(UIControlStateNormal)];
|
|||
|
|
[self.recordBtn setTitle:@"记录" forState:(UIControlStateNormal)];
|
|||
|
|
[self.recordBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|||
|
|
self.recordBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|||
|
|
[self.recordBtn addTarget:self action:@selector(recordAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.bgView addSubview:self.recordBtn];
|
|||
|
|
|
|||
|
|
CGFloat topMargin = self.recordBtn.bottom+5;
|
|||
|
|
CGFloat margin = 11;
|
|||
|
|
CGFloat space = 8;
|
|||
|
|
CGFloat itemWidth = (SCREEN_WIDTH - margin*2 - space*3) / 4;
|
|||
|
|
CGFloat itemHeight = itemWidth/82*99;;
|
|||
|
|
for (int i = 0; i < giftMaxCount; i++) {
|
|||
|
|
QXSkyPraizeSubView *giftView;
|
|||
|
|
if (i < 4) {
|
|||
|
|
/// 第一行4个
|
|||
|
|
giftView = [[QXSkyPraizeSubView alloc] initWithFrame:CGRectMake(margin+(itemWidth+space)*i, topMargin, itemWidth, itemHeight)];
|
|||
|
|
giftView.titleLabel.text = [NSString stringWithFormat:@"%d",i];
|
|||
|
|
[self.allViewsArray replaceObjectAtIndex:i withObject:giftView];
|
|||
|
|
}else if (i > 3 && i < 6){
|
|||
|
|
/// 第二行两个
|
|||
|
|
if (i == 4) {
|
|||
|
|
giftView = [[QXSkyPraizeSubView alloc] initWithFrame:CGRectMake(margin, topMargin+itemHeight+space, itemWidth, itemHeight)];
|
|||
|
|
giftView.titleLabel.text = [NSString stringWithFormat:@"%d",11];
|
|||
|
|
[self.allViewsArray replaceObjectAtIndex:11 withObject:giftView];
|
|||
|
|
}else{
|
|||
|
|
giftView = [[QXSkyPraizeSubView alloc] initWithFrame:CGRectMake(margin+(itemWidth+space)*3, topMargin+itemHeight+space, itemWidth, itemHeight)];
|
|||
|
|
[self.allViewsArray replaceObjectAtIndex:4 withObject:giftView];
|
|||
|
|
giftView.titleLabel.text = [NSString stringWithFormat:@"%d",4];
|
|||
|
|
}
|
|||
|
|
}else if (i > 5 && i < 8){
|
|||
|
|
/// 第三行两个
|
|||
|
|
if (i == 6) {
|
|||
|
|
giftView = [[QXSkyPraizeSubView alloc] initWithFrame:CGRectMake(margin, topMargin+(itemHeight+space)*2, itemWidth, itemHeight)];
|
|||
|
|
[self.allViewsArray replaceObjectAtIndex:10 withObject:giftView];
|
|||
|
|
giftView.titleLabel.text = [NSString stringWithFormat:@"%d",10];
|
|||
|
|
}else{
|
|||
|
|
giftView = [[QXSkyPraizeSubView alloc] initWithFrame:CGRectMake(margin+(itemWidth+space)*3, topMargin+(itemHeight+space)*2, itemWidth, itemHeight)];
|
|||
|
|
[self.allViewsArray replaceObjectAtIndex:5 withObject:giftView];
|
|||
|
|
giftView.titleLabel.text = [NSString stringWithFormat:@"%d",5];
|
|||
|
|
}
|
|||
|
|
}else{
|
|||
|
|
giftView = [[QXSkyPraizeSubView alloc] initWithFrame:CGRectMake(margin+(itemWidth+space)*(i%4), topMargin+(itemHeight+space)*3, itemWidth, itemHeight)];
|
|||
|
|
[self.allViewsArray replaceObjectAtIndex:11-(i-6) withObject:giftView];
|
|||
|
|
giftView.titleLabel.text = [NSString stringWithFormat:@"%d",11-(i-6)];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[self.bgView addSubview:giftView];
|
|||
|
|
}
|
|||
|
|
[self resetViews];
|
|||
|
|
|
|||
|
|
CGFloat btnWidth = ScaleWidth(109);
|
|||
|
|
CGFloat btnMargin = (SCREEN_WIDTH- ScaleWidth(109)*3)/4;
|
|||
|
|
QXSkyDrawBtn *oneBtn = [[QXSkyDrawBtn alloc] initWithFrame:CGRectMake(btnMargin, self.bgView.height-ScaleWidth(34)-20, btnWidth, ScaleWidth(34))];
|
|||
|
|
oneBtn.btnType = QXSkyDrawBtnTypeOne;
|
|||
|
|
self.oneBtn = oneBtn;
|
|||
|
|
self.oneBtn.hidden = YES;
|
|||
|
|
[oneBtn addTarget:self action:@selector(startAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.bgView addSubview:oneBtn];
|
|||
|
|
|
|||
|
|
QXSkyDrawBtn *tenBtn = [[QXSkyDrawBtn alloc] initWithFrame:CGRectMake(self.oneBtn.right+btnMargin, self.oneBtn.top, btnWidth, ScaleWidth(34))];
|
|||
|
|
tenBtn.btnType = QXSkyDrawBtnTypeTen;
|
|||
|
|
self.tenBtn = tenBtn;
|
|||
|
|
self.tenBtn.hidden = YES;
|
|||
|
|
[tenBtn addTarget:self action:@selector(startAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.bgView addSubview:tenBtn];
|
|||
|
|
|
|||
|
|
QXSkyDrawBtn *hundredBtn = [[QXSkyDrawBtn alloc] initWithFrame:CGRectMake(tenBtn.right+btnMargin, self.oneBtn.top, btnWidth, ScaleWidth(34))];
|
|||
|
|
hundredBtn.btnType = QXSkyDrawBtnTypeHundred;
|
|||
|
|
self.hundredBtn = hundredBtn;
|
|||
|
|
self.hundredBtn.hidden = YES;
|
|||
|
|
[hundredBtn addTarget:self action:@selector(startAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.bgView addSubview:hundredBtn];
|
|||
|
|
|
|||
|
|
self.soundBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-75-15, self.oneBtn.top-20-20, 75, 20)];
|
|||
|
|
[self.soundBtn addTarget:self action:@selector(soundAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.soundBtn setTitle:@"音效" forState:(UIControlStateNormal)];
|
|||
|
|
[self.soundBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|||
|
|
self.soundBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|||
|
|
[self.soundBtn setImage:[UIImage imageNamed:@"sky_switch_off"] forState:(UIControlStateNormal)];
|
|||
|
|
[self.soundBtn setImage:[UIImage imageNamed:@"sky_switch_on"] forState:(UIControlStateSelected)];
|
|||
|
|
self.soundBtn.selected = YES;
|
|||
|
|
[self.bgView addSubview:self.soundBtn];
|
|||
|
|
|
|||
|
|
|
|||
|
|
self.specialBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2+15, self.oneBtn.top-20-20, 75, 20)];
|
|||
|
|
[self.specialBtn addTarget:self action:@selector(specialAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.specialBtn setTitle:@"特效" forState:(UIControlStateNormal)];
|
|||
|
|
[self.specialBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|||
|
|
self.specialBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
|||
|
|
[self.specialBtn setImage:[UIImage imageNamed:@"sky_switch_off"] forState:(UIControlStateNormal)];
|
|||
|
|
[self.specialBtn setImage:[UIImage imageNamed:@"sky_switch_on"] forState:(UIControlStateSelected)];
|
|||
|
|
self.specialBtn.selected = YES;
|
|||
|
|
[self.bgView addSubview:self.specialBtn];
|
|||
|
|
|
|||
|
|
[self.soundBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleRight) imageTitleSpace:2];
|
|||
|
|
[self.specialBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleRight) imageTitleSpace:2];
|
|||
|
|
self.isOpenSound = YES;
|
|||
|
|
self.isOpenSpecial = YES;
|
|||
|
|
|
|||
|
|
|
|||
|
|
self.coinView = [[UIView alloc] initWithFrame:CGRectMake((self.bgView.width-100)/2, topMargin+(itemHeight+space)*3-ScaleWidth(28)-6, 100,ScaleWidth(28))];
|
|||
|
|
[self.coinView addRoundedCornersWithRadius:ScaleWidth(14)];
|
|||
|
|
self.coinView.backgroundColor = RGB16A(0x2d449f,0.5);
|
|||
|
|
[self.bgView addSubview:self.coinView];
|
|||
|
|
|
|||
|
|
self.coinBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, self.coinView.height)];
|
|||
|
|
[self.coinBtn setTitleColor:RGB16(0xF8E837) forState:(UIControlStateNormal)];
|
|||
|
|
[self.coinBtn setTitle:@"-" forState:(UIControlStateNormal)];
|
|||
|
|
[self.coinBtn setImage:[UIImage imageNamed:@"sky_item_coin"] forState:(UIControlStateNormal)];
|
|||
|
|
self.coinBtn.titleLabel.font = [UIFont systemFontOfSize:10];
|
|||
|
|
self.coinBtn.userInteractionEnabled = NO;
|
|||
|
|
[self.coinView addSubview:self.coinBtn];
|
|||
|
|
|
|||
|
|
self.exchangeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.coinView.width-50, 0, 50, self.coinView.height)];
|
|||
|
|
[self.exchangeBtn setTitle:@"去兑换" forState:(UIControlStateNormal)];
|
|||
|
|
[self.exchangeBtn setTitleColor:RGB16(0xF8E837) forState:(UIControlStateNormal)];
|
|||
|
|
self.exchangeBtn.titleLabel.font = [UIFont systemFontOfSize:10];
|
|||
|
|
[self.exchangeBtn addTarget:self action:@selector(exchangeAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|||
|
|
[self.coinView addSubview:self.exchangeBtn];
|
|||
|
|
|
|||
|
|
MJWeakSelf
|
|||
|
|
self.centerView = [[QXDrawGiftCenterView alloc] initWithFrame:CGRectMake((self.bgView.width-ScaleWidth(148))/2, topMargin+itemHeight, ScaleWidth(148), ScaleWidth(180))];
|
|||
|
|
self.centerView.hidden = YES;
|
|||
|
|
self.centerView.startBlock = ^{
|
|||
|
|
if (weakSelf.startBlock) {
|
|||
|
|
weakSelf.startBlock();
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
self.centerView.type = QXDrawGiftCenterTypeWait;
|
|||
|
|
self.centerView.activityType = QXActivityTypeSky;
|
|||
|
|
[self.bgView addSubview:self.centerView];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)getMyWallet{
|
|||
|
|
MJWeakSelf
|
|||
|
|
[[QXRequset shareInstance] getWithUrl:QXWallet parameters:@{@"token":[QXGlobal shareGlobal].loginModel.token?[QXGlobal shareGlobal].loginModel.token:@""} needCache:NO success:^(id responseObject) {
|
|||
|
|
double coin = [responseObject[@"data"][@"coin"] doubleValue];
|
|||
|
|
NSString *coinStr = [NSString stringWithFormat:@"%.2f",coin];
|
|||
|
|
[weakSelf.coinBtn setTitle:[NSString stringWithFormat:@" %@",coinStr] forState:(UIControlStateNormal)];
|
|||
|
|
[weakSelf.coinBtn sizeToFit];
|
|||
|
|
CGFloat allWidth = weakSelf.coinBtn.width + self.exchangeBtn.width+15;
|
|||
|
|
weakSelf.coinView.width = allWidth;
|
|||
|
|
weakSelf.coinView.x = (self.bgView.width-allWidth)/2;
|
|||
|
|
weakSelf.coinBtn.frame = CGRectMake(10, 0, weakSelf.coinBtn.width, weakSelf.coinView.height);
|
|||
|
|
weakSelf.exchangeBtn.frame = CGRectMake(allWidth-weakSelf.exchangeBtn.width, 0, weakSelf.exchangeBtn.width, weakSelf.coinView.height);
|
|||
|
|
} fail:^(NSError *error, NSString *msg, NSURLSessionDataTask *task) {
|
|||
|
|
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
-(void)setGiftModel:(QXGiftModel *)giftModel{
|
|||
|
|
_giftModel = giftModel;
|
|||
|
|
[self getGiftList];
|
|||
|
|
[self getMyWallet];
|
|||
|
|
}
|
|||
|
|
-(void)updateProgress:(QXXLHModel*)model{
|
|||
|
|
if (self.model) {
|
|||
|
|
self.model.xlh_data = model;
|
|||
|
|
self.centerView.model = self.model;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
-(void)getGiftList{
|
|||
|
|
if (![self.giftModel.gift_bag isExist]) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (![self.roomId isExist]) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
// if (self.model) {
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
MJWeakSelf
|
|||
|
|
[[QXRequset shareInstance] postWithUrl:[NSString stringWithFormat:@"%@%@",ServerUrl,@"api/BlindBoxTurntable/get_gift_list"] parameters:@{@"gift_bag_id":self.giftModel.gift_bag?self.giftModel.gift_bag:@"",@"room_id":self.roomId?self.roomId:@""} needCache:NO success:^(id responseObject) {
|
|||
|
|
QXGiftActivityModel *model = [QXGiftActivityModel yy_modelWithJSON:responseObject[@"data"]];
|
|||
|
|
weakSelf.model = model;
|
|||
|
|
weakSelf.centerView.model = model;
|
|||
|
|
for (int i = 0; i < model.gift_list.count; i++) {
|
|||
|
|
QXSkyPraizeSubView* subview = weakSelf.allViewsArray[i];
|
|||
|
|
subview.giftModel = model.gift_list[i];
|
|||
|
|
}
|
|||
|
|
[weakSelf.oneBtn.giftCoin setTitle:[NSString stringWithFormat:@"%@币一次",model.box_price] forState:(UIControlStateNormal)];
|
|||
|
|
[weakSelf.tenBtn.giftCoin setTitle:[NSString stringWithFormat:@"%ld币一次",model.box_price.integerValue*10] forState:(UIControlStateNormal)];
|
|||
|
|
[weakSelf.hundredBtn.giftCoin setTitle:[NSString stringWithFormat:@"%ld币一次",model.box_price.integerValue*100] forState:(UIControlStateNormal)];
|
|||
|
|
weakSelf.oneBtn.hidden = NO;
|
|||
|
|
weakSelf.tenBtn.hidden = NO;
|
|||
|
|
weakSelf.hundredBtn.hidden = NO;
|
|||
|
|
} fail:^(NSError *error, NSString *msg, NSURLSessionDataTask *task) {
|
|||
|
|
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)drawGiftWithNum:(NSString*)num{
|
|||
|
|
NSDictionary *parameters = @{
|
|||
|
|
@"gift_bag_id":self.giftModel.gift_bag,
|
|||
|
|
@"gift_user_ids":self.userIds,
|
|||
|
|
@"room_id":self.roomId,
|
|||
|
|
@"num":num
|
|||
|
|
};
|
|||
|
|
self.isDrawing = YES;
|
|||
|
|
MJWeakSelf
|
|||
|
|
[[QXRequset shareInstance] postWithUrl:[NSString stringWithFormat:@"%@%@",ServerUrl,@"api/BlindBoxTurntable/draw_gift"] parameters:parameters needCache:NO success:^(id responseObject) {
|
|||
|
|
QXDrawGiftResultModel *model = [QXDrawGiftResultModel yy_modelWithJSON:responseObject[@"data"]];
|
|||
|
|
weakSelf.drawResultModel = model;
|
|||
|
|
[weakSelf.targetArrayIndex removeAllObjects];
|
|||
|
|
// [weakSelf resetViews];
|
|||
|
|
for (int i = 0; i < model.reslut_list.count; i++) {
|
|||
|
|
QXDrawGiftModel *md = model.reslut_list[i];
|
|||
|
|
for (int j = 0; j < weakSelf.model.gift_list.count; j++) {
|
|||
|
|
QXDrawGiftModel*gift = weakSelf.model.gift_list[j];
|
|||
|
|
if ([md.gift_id isEqualToString:gift.gift_id]) {
|
|||
|
|
[weakSelf.targetArrayIndex addObject:[NSNumber numberWithInt:j]];
|
|||
|
|
if (j < 12) {
|
|||
|
|
QXSkyPraizeSubView *subView = weakSelf.allViewsArray[j];
|
|||
|
|
subView.count = md.count;
|
|||
|
|
if (!weakSelf.isOpenSpecial) {
|
|||
|
|
subView.resultView.hidden = NO;
|
|||
|
|
subView.isSelected = YES;
|
|||
|
|
weakSelf.isDrawing = NO;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (weakSelf.isOpenSound) {
|
|||
|
|
[weakSelf.player seekToTime:CMTimeMake(0, 1)];
|
|||
|
|
[weakSelf.player play];
|
|||
|
|
}
|
|||
|
|
if (weakSelf.isOpenSpecial) {
|
|||
|
|
[weakSelf startFastAnimate];
|
|||
|
|
}else{
|
|||
|
|
[weakSelf animateFinishedSendGift];
|
|||
|
|
}
|
|||
|
|
} fail:^(NSError *error, NSString *msg, NSURLSessionDataTask *task) {
|
|||
|
|
weakSelf.isDrawing = NO;
|
|||
|
|
showToast(msg);
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
|
|||
|
|
return touch.view == self;
|
|||
|
|
}
|
|||
|
|
-(void)specialAction:(UIButton*)sender{
|
|||
|
|
sender.selected = !sender.selected;
|
|||
|
|
self.isOpenSpecial = sender.selected;
|
|||
|
|
if (self.isOpenSpecial) {
|
|||
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"draw_music" ofType:@"mp3"];
|
|||
|
|
_player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:path]];
|
|||
|
|
}else{
|
|||
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"no_animate_draw_music" ofType:@"mp3"];
|
|||
|
|
_player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:path]];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
-(void)soundAction:(UIButton*)sender{
|
|||
|
|
sender.selected = !sender.selected;
|
|||
|
|
self.isOpenSound = sender.selected;
|
|||
|
|
if (self.isOpenSpecial) {
|
|||
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"draw_music" ofType:@"mp3"];
|
|||
|
|
_player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:path]];
|
|||
|
|
}else{
|
|||
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"no_animate_draw_music" ofType:@"mp3"];
|
|||
|
|
_player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:path]];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
-(void)startAction:(QXSkyDrawBtn*)sender{
|
|||
|
|
if (self.isDrawing) {
|
|||
|
|
showToast(@"正在抽奖中");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
[self resetViews];
|
|||
|
|
[self drawGiftWithNum:[NSString stringWithFormat:@"%ld",sender.btnType]];
|
|||
|
|
|
|||
|
|
/// 获取目标礼物
|
|||
|
|
|
|||
|
|
// [self getTargetGift];
|
|||
|
|
// [self startFastAnimate];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)exchangeAction{
|
|||
|
|
QXDiamondViewController *vc = [[QXDiamondViewController alloc] init];
|
|||
|
|
[self.viewController.navigationController pushViewController:vc animated:YES];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)resetViews{
|
|||
|
|
|
|||
|
|
self.isDrawing = NO;
|
|||
|
|
self.targetIndex = -1;
|
|||
|
|
self.currentIndex = -1;
|
|||
|
|
self.roundCount = 0;
|
|||
|
|
self.delayTime = 0.2;
|
|||
|
|
[self.targetArrayIndex removeAllObjects];
|
|||
|
|
[self.finishTargetArrayIndex removeAllObjects];
|
|||
|
|
if (self.currentGiftView != nil) {
|
|||
|
|
self.currentGiftView.isSelected = NO;
|
|||
|
|
[self.currentGiftView stopPulseAnimationWithLayer];
|
|||
|
|
}
|
|||
|
|
for (QXSkyPraizeSubView *giftView in self.allViewsArray) {
|
|||
|
|
giftView.isSelected = NO;
|
|||
|
|
giftView.count = @"0";
|
|||
|
|
giftView.resultView.hidden = YES;
|
|||
|
|
[giftView stopPulseAnimationWithLayer];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)startFastAnimate{
|
|||
|
|
self.currentGiftView = self.allViewsArray.firstObject;
|
|||
|
|
self.currentGiftView.isSelected = YES;
|
|||
|
|
[self stopFastAnimate];
|
|||
|
|
if (_fastTimer == nil) {
|
|||
|
|
_fastTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
|
|||
|
|
}
|
|||
|
|
// dispatch_source_set_timer(_fastTimer,
|
|||
|
|
// dispatch_time(DISPATCH_TIME_NOW, 0),
|
|||
|
|
// NSEC_PER_SEC * 0.06, // 间隔0.1秒
|
|||
|
|
// NSEC_PER_SEC * 0.01); // 允许误差0.01秒
|
|||
|
|
|
|||
|
|
dispatch_source_set_timer(_fastTimer,
|
|||
|
|
dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC),
|
|||
|
|
DISPATCH_TIME_FOREVER, // 使用一次性模式
|
|||
|
|
0.01 * NSEC_PER_SEC);
|
|||
|
|
if (self.isOpenSound) {
|
|||
|
|
[self.player seekToTime:CMTimeMake(0, 1)];
|
|||
|
|
[self.player play];
|
|||
|
|
}
|
|||
|
|
__weak typeof(self) weakSelf = self;
|
|||
|
|
dispatch_source_set_event_handler(_fastTimer, ^{
|
|||
|
|
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|||
|
|
if (!strongSelf) return;
|
|||
|
|
// 如果需要更新UI,切换到主线程
|
|||
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|||
|
|
strongSelf.roundCount++;
|
|||
|
|
if ((strongSelf.roundCount / giftMaxCount == minRoundCount) && strongSelf.startType != QXSkyDrawBtnTypeOne) {
|
|||
|
|
BOOL has = NO;
|
|||
|
|
for (NSNumber *index in self.finishTargetArrayIndex) {
|
|||
|
|
if (index.integerValue == self.currentIndex) {
|
|||
|
|
has = YES;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
self.currentGiftView.isSelected = NO;
|
|||
|
|
if (has) {
|
|||
|
|
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
|||
|
|
giftView.isSelected = YES;
|
|||
|
|
}else{
|
|||
|
|
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
|||
|
|
giftView.isSelected = NO;
|
|||
|
|
}
|
|||
|
|
}else{
|
|||
|
|
/// 把上一个选中状态置为未选中
|
|||
|
|
strongSelf.currentGiftView.isSelected = NO;
|
|||
|
|
}
|
|||
|
|
/// 计算当前下标
|
|||
|
|
strongSelf.currentIndex = strongSelf.roundCount%giftMaxCount;
|
|||
|
|
/// 获取当前选中的view 并设置为选中状态
|
|||
|
|
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[strongSelf.currentIndex];
|
|||
|
|
giftView.isSelected = YES;
|
|||
|
|
|
|||
|
|
/// 重新赋值给选中view
|
|||
|
|
strongSelf.currentGiftView = giftView;
|
|||
|
|
|
|||
|
|
if (strongSelf.roundCount / giftMaxCount == minRoundCount) {
|
|||
|
|
for (NSNumber *index in strongSelf.targetArrayIndex) {
|
|||
|
|
if (strongSelf.currentIndex == index.integerValue) {
|
|||
|
|
QXSkyPraizeSubView *giftView = strongSelf.allViewsArray[index.integerValue];
|
|||
|
|
giftView.isSelected = YES;
|
|||
|
|
giftView.resultView.hidden = NO;
|
|||
|
|
[giftView startPulseAnimationWithLayer];
|
|||
|
|
[strongSelf.targetArrayIndex removeObject:index];
|
|||
|
|
[strongSelf.finishTargetArrayIndex addObject:index];
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
dispatch_source_set_timer(strongSelf.fastTimer,
|
|||
|
|
dispatch_time(DISPATCH_TIME_NOW, 0.03 * NSEC_PER_SEC),
|
|||
|
|
DISPATCH_TIME_FOREVER,
|
|||
|
|
0.01 * NSEC_PER_SEC);
|
|||
|
|
if (strongSelf.targetArrayIndex.count == 0) {
|
|||
|
|
strongSelf.isDrawing = NO;
|
|||
|
|
[strongSelf stopFastAnimate];
|
|||
|
|
[strongSelf animateFinishedSendGift];
|
|||
|
|
}
|
|||
|
|
// }
|
|||
|
|
}else{
|
|||
|
|
strongSelf.delayTime = strongSelf.delayTime-0.02;
|
|||
|
|
if (strongSelf.delayTime <= 0.03) {
|
|||
|
|
strongSelf.delayTime = 0.03;
|
|||
|
|
}
|
|||
|
|
dispatch_source_set_timer(strongSelf.fastTimer,
|
|||
|
|
dispatch_time(DISPATCH_TIME_NOW, strongSelf.delayTime * NSEC_PER_SEC),
|
|||
|
|
DISPATCH_TIME_FOREVER,
|
|||
|
|
0.01 * NSEC_PER_SEC);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
dispatch_resume(_fastTimer);
|
|||
|
|
}
|
|||
|
|
-(void)animateFinishedSendGift{
|
|||
|
|
NSDictionary *parameters = @{
|
|||
|
|
@"send_id":self.drawResultModel.blind_box_turntable_id?self.drawResultModel.blind_box_turntable_id:@""
|
|||
|
|
};
|
|||
|
|
[[QXRequset shareInstance] postWithUrl:[NSString stringWithFormat:@"%@%@",ServerUrl,@"api/BlindBoxTurntable/gift_send"] parameters:parameters needCache:NO success:^(id responseObject) {
|
|||
|
|
|
|||
|
|
} fail:^(NSError *error, NSString *msg, NSURLSessionDataTask *task) {
|
|||
|
|
|
|||
|
|
showToast(msg);
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)stopFastAnimate{
|
|||
|
|
if (_fastTimer != nil) {
|
|||
|
|
dispatch_source_cancel(_fastTimer);
|
|||
|
|
_fastTimer = nil;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)pauseGCDTimer {
|
|||
|
|
if (_fastTimer) {
|
|||
|
|
dispatch_suspend(_fastTimer);
|
|||
|
|
NSLog(@"GCD定时器已暂停");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
- (void)resumeGCDTimer {
|
|||
|
|
if (_fastTimer) {
|
|||
|
|
dispatch_resume(_fastTimer);
|
|||
|
|
NSLog(@"GCD定时器已恢复");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
-(void)ruleAction{
|
|||
|
|
self.ruleView.rule = self.model.rule_url;
|
|||
|
|
[self.ruleView showInView:self];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)poolAction{
|
|||
|
|
self.poolView.roomId = self.roomId;
|
|||
|
|
self.poolView.giftModel = self.giftModel;
|
|||
|
|
|
|||
|
|
[self.poolView showInView:self];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)recordAction{
|
|||
|
|
self.recordView.roomId = self.roomId;
|
|||
|
|
self.recordView.giftModel = self.giftModel;
|
|||
|
|
|
|||
|
|
[self.recordView showInView:self];
|
|||
|
|
}
|
|||
|
|
-(NSMutableArray *)allViewsArray{
|
|||
|
|
if (!_allViewsArray) {
|
|||
|
|
_allViewsArray = [NSMutableArray arrayWithArray:@[@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@""]];
|
|||
|
|
}
|
|||
|
|
return _allViewsArray;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(NSMutableArray *)targetArrayIndex{
|
|||
|
|
if (!_targetArrayIndex) {
|
|||
|
|
_targetArrayIndex = [NSMutableArray array];
|
|||
|
|
}
|
|||
|
|
return _targetArrayIndex;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
-(AVPlayer *)player{
|
|||
|
|
if (!_player) {
|
|||
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"draw_music" ofType:@"mp3"];
|
|||
|
|
_player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:path]];
|
|||
|
|
}
|
|||
|
|
return _player;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
-(NSMutableArray *)finishTargetArrayIndex{
|
|||
|
|
if (!_finishTargetArrayIndex) {
|
|||
|
|
_finishTargetArrayIndex = [NSMutableArray array];
|
|||
|
|
}
|
|||
|
|
return _finishTargetArrayIndex;
|
|||
|
|
}
|
|||
|
|
-(QXSkyPraizeRuleView *)ruleView{
|
|||
|
|
if (!_ruleView) {
|
|||
|
|
_ruleView = [[QXSkyPraizeRuleView alloc] init];
|
|||
|
|
}
|
|||
|
|
return _ruleView;
|
|||
|
|
}
|
|||
|
|
-(QXSkyPraizePoolView *)poolView{
|
|||
|
|
if (!_poolView) {
|
|||
|
|
_poolView = [[QXSkyPraizePoolView alloc] init];
|
|||
|
|
}
|
|||
|
|
return _poolView;
|
|||
|
|
}
|
|||
|
|
-(QXSkyPraizeRecordView *)recordView{
|
|||
|
|
if (!_recordView) {
|
|||
|
|
_recordView = [[QXSkyPraizeRecordView alloc] init];
|
|||
|
|
}
|
|||
|
|
return _recordView;
|
|||
|
|
}
|
|||
|
|
-(void)showInView:(UIView *)view{
|
|||
|
|
[self getGiftList];
|
|||
|
|
[self resetViews];
|
|||
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|||
|
|
[view addSubview:self];
|
|||
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|||
|
|
self.bgView.y = SCREEN_HEIGHT-ScaleWidth(663);
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
-(void)hide{
|
|||
|
|
[self stopFastAnimate];
|
|||
|
|
// [self stopSlowAnimate];
|
|||
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|||
|
|
self.bgView.y = SCREEN_HEIGHT;
|
|||
|
|
} completion:^(BOOL finished) {
|
|||
|
|
[self removeFromSuperview];
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
-(void)destroyViews{
|
|||
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|||
|
|
}
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
|
|||
|
|
@implementation QXSkyPraizeSubView
|
|||
|
|
|
|||
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|||
|
|
{
|
|||
|
|
self = [super initWithFrame:frame];
|
|||
|
|
if (self) {
|
|||
|
|
[self initSubviews];
|
|||
|
|
}
|
|||
|
|
return self;
|
|||
|
|
}
|
|||
|
|
-(void)initSubviews{
|
|||
|
|
|
|||
|
|
|
|||
|
|
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sky_item_nor"]];
|
|||
|
|
[self addSubview:self.bgImageView];
|
|||
|
|
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.edges.equalTo(self);
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
self.giftImageView = [[UIImageView alloc] init];
|
|||
|
|
[self addSubview:self.giftImageView];
|
|||
|
|
[self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.top.mas_equalTo(7);
|
|||
|
|
make.width.height.mas_equalTo(ScaleWidth(50));
|
|||
|
|
make.centerX.equalTo(self);
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
self.titleLabel = [[UILabel alloc] init];
|
|||
|
|
self.titleLabel.font = [UIFont boldSystemFontOfSize:12];
|
|||
|
|
self.titleLabel.textColor = RGB16(0xffffff);
|
|||
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|||
|
|
[self addSubview:self.titleLabel];
|
|||
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.top.equalTo(self.giftImageView.mas_bottom).offset(4);
|
|||
|
|
make.height.mas_equalTo(ScaleWidth(14));
|
|||
|
|
make.centerX.equalTo(self);
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
self.giftCoin = [[UIButton alloc] init];
|
|||
|
|
self.giftCoin.userInteractionEnabled = NO;
|
|||
|
|
[self.giftCoin setTitleColor:RGB16(0xC7BF62) forState:(UIControlStateNormal)];
|
|||
|
|
[self.giftCoin setImage:[UIImage imageNamed:@"sky_item_coin"] forState:(UIControlStateNormal)];
|
|||
|
|
self.giftCoin.titleLabel.font = [UIFont systemFontOfSize:10];
|
|||
|
|
[self addSubview:self.giftCoin];
|
|||
|
|
[self.giftCoin mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.centerX.equalTo(self);
|
|||
|
|
make.top.equalTo(self.titleLabel.mas_bottom);
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
self.resultView = [[UIView alloc] init];
|
|||
|
|
self.resultView.hidden = YES;;
|
|||
|
|
[self addSubview:self.resultView];
|
|||
|
|
[self.resultView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.left.right.top.equalTo(self);
|
|||
|
|
make.height.mas_equalTo(54);
|
|||
|
|
}];
|
|||
|
|
self.resultBgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sky_item_top_bg"]];
|
|||
|
|
[self.resultView addSubview:self.resultBgImageView];
|
|||
|
|
[self.resultBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.edges.equalTo(self.resultView);
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
self.countLabel = [[UILabel alloc] init];
|
|||
|
|
self.countLabel.font = [UIFont fontWithName:@"YouSheBiaoTiHei" size:18];
|
|||
|
|
self.countLabel.textColor = RGB16(0x024AA7);
|
|||
|
|
self.countLabel.textAlignment = NSTextAlignmentCenter;
|
|||
|
|
[self.resultView addSubview:self.countLabel];
|
|||
|
|
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|||
|
|
make.top.mas_equalTo(12);
|
|||
|
|
make.height.mas_equalTo(ScaleWidth(20));
|
|||
|
|
make.centerX.equalTo(self.resultView);
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
-(void)setCount:(NSString *)count{
|
|||
|
|
_count = count;
|
|||
|
|
if (count.integerValue > 0) {
|
|||
|
|
// self.resultView.hidden = YES;
|
|||
|
|
// }else{
|
|||
|
|
// self.resultView.hidden = NO;
|
|||
|
|
self.countLabel.text = [NSString stringWithFormat:@"X%@",count];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
-(void)setGiftModel:(QXDrawGiftModel *)giftModel{
|
|||
|
|
_giftModel = giftModel;
|
|||
|
|
self.titleLabel.text = giftModel.gift_name;
|
|||
|
|
[self.giftCoin setTitle:giftModel.gift_price forState:(UIControlStateNormal)];
|
|||
|
|
NSString *encodedQuery = [giftModel.base_image stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
|||
|
|
NSURL *imageUrl = [NSURL URLWithString:encodedQuery];
|
|||
|
|
[self.giftImageView sd_setImageWithURL:imageUrl];
|
|||
|
|
}
|
|||
|
|
-(void)setIsSelected:(BOOL)isSelected{
|
|||
|
|
_isSelected = isSelected;
|
|||
|
|
self.bgImageView.image = [UIImage imageNamed:isSelected?@"sky_item_sel":@"sky_item_nor"];
|
|||
|
|
}
|
|||
|
|
- (void)startPulseAnimationWithLayer {
|
|||
|
|
CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
|
|||
|
|
pulseAnimation.duration = 0.5;
|
|||
|
|
pulseAnimation.fromValue = @0.9;
|
|||
|
|
pulseAnimation.toValue = @1.1;
|
|||
|
|
pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
|||
|
|
pulseAnimation.autoreverses = YES;
|
|||
|
|
pulseAnimation.repeatCount = HUGE_VALF; // 无限循环
|
|||
|
|
|
|||
|
|
[self.layer addAnimation:pulseAnimation forKey:@"pulse"];
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 停止动画
|
|||
|
|
- (void)stopPulseAnimationWithLayer {
|
|||
|
|
[self.layer removeAnimationForKey:@"pulse"];
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
|
|||
|
|
@implementation QXSkyDrawBtn
|
|||
|
|
|
|||
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|||
|
|
{
|
|||
|
|
self = [super initWithFrame:frame];
|
|||
|
|
if (self) {
|
|||
|
|
[self initSubviews];
|
|||
|
|
}
|
|||
|
|
return self;
|
|||
|
|
}
|
|||
|
|
-(void)initSubviews{
|
|||
|
|
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sky_touch_bg"]];
|
|||
|
|
self.bgImageView.frame = self.bounds;
|
|||
|
|
[self addSubview:self.bgImageView];
|
|||
|
|
|
|||
|
|
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.width, 16)];
|
|||
|
|
self.titleLabel.font = [UIFont systemFontOfSize:12];
|
|||
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|||
|
|
self.titleLabel.textColor = RGB16(0xA18710);
|
|||
|
|
[self addSubview:self.titleLabel];
|
|||
|
|
|
|||
|
|
self.giftCoin = [[UIButton alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom, self.width, 16)];
|
|||
|
|
[self.giftCoin setTitleColor:RGB16(0xA18710) forState:(UIControlStateNormal)];
|
|||
|
|
[self.giftCoin setImage:[UIImage imageNamed:@"sky_item_coin"] forState:(UIControlStateNormal)];
|
|||
|
|
self.giftCoin.titleLabel.font = [UIFont systemFontOfSize:10];
|
|||
|
|
self.giftCoin.userInteractionEnabled = NO;
|
|||
|
|
[self addSubview:self.giftCoin];
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
-(void)setBtnType:(QXSkyDrawBtnType)btnType{
|
|||
|
|
// /// 抽一次
|
|||
|
|
// QXSkyDrawBtnTypeOne = 0,
|
|||
|
|
// /// 抽10次
|
|||
|
|
// QXSkyDrawBtnTypeTen ,
|
|||
|
|
// /// 抽100次
|
|||
|
|
// QXSkyDrawBtnTypeHundred ,
|
|||
|
|
_btnType = btnType;
|
|||
|
|
switch (btnType) {
|
|||
|
|
case QXSkyDrawBtnTypeOne:
|
|||
|
|
{
|
|||
|
|
self.titleLabel.text = @"抽一次";
|
|||
|
|
[self.giftCoin setTitle:@"10币一次" forState:(UIControlStateNormal)];
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case QXSkyDrawBtnTypeTen:
|
|||
|
|
{
|
|||
|
|
self.titleLabel.text = @"抽十次";
|
|||
|
|
[self.giftCoin setTitle:@"100币一次" forState:(UIControlStateNormal)];
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case QXSkyDrawBtnTypeHundred:
|
|||
|
|
{
|
|||
|
|
self.titleLabel.text = @"抽百次";
|
|||
|
|
[self.giftCoin setTitle:@"1000币一次" forState:(UIControlStateNormal)];
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
|
|||
|
|
default:
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
@end
|