123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- //
- // JXWheelView.m
- // shiku_im
- //
- // Created by 123 on 2020/6/6.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXWheelView.h"
-
- @interface LotteryItem : NSObject
- @property(nonatomic,copy)NSNumber *time;
- @property(nonatomic,assign)int angle;
- @property(nonatomic,assign)int selectIndex;
- @end
- @implementation LotteryItem
- @end
- @interface JXWheelView ()
- @property(nonatomic,strong)UIView* vLine;
- @property(nonatomic,strong)CABasicAnimation *rotateAnimation;
- @property(nonatomic,strong)NSArray *arrAngle;
- @property (nonatomic,strong)UIButton *jiantouBtn; //抽奖按钮
- @property (nonatomic,strong)UIImageView *rotalIMG; //转盘背景
- @end
- @implementation JXWheelView
- -(instancetype)initWithFrame:(CGRect)frame{
- if (self=[super initWithFrame:frame]) {
-
-
- UIImageView* rotalIMG = [[UIImageView alloc] initWithFrame:self.bounds];
- rotalIMG.image = [UIImage imageNamed:@"zhuanpanback"];
- [self addSubview:rotalIMG];
- self.rotalIMG=rotalIMG;
-
- self.jiantouBtn = [[UIButton alloc]init];
- [self.jiantouBtn setImage:[UIImage imageNamed:@"nodeWheel"] forState:UIControlStateNormal];
- [self addSubview:self.jiantouBtn];
- [self.jiantouBtn addTarget:self action:@selector(playButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- [self.jiantouBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.rotalIMG.mas_centerX);
- make.centerY.mas_equalTo(self.rotalIMG.mas_centerY);
- //make.width.mas_equalTo(113);
- }];
- _arrAngle = @[@[@[@"1",@"15"],@[@"165",@"195"],@[@"345",@"360"]],
- @[@[@"105",@"135"],@[@"285",@"315"]],
- @[@[@"45",@"75"],@[@"225",@"255"]],@[@[@"15",@"45"],
- @[@"75",@"105"],@[@"135",@"165"],@[@"195",@"225"],@[@"255",@"285"],@[@"315",@"345"]]];
-
-
- _arrAngle = @[@[@[@"1",@"15"],@[@"15",@"30"],@[@"45",@"60"],@[@"60",@"75"],@[@"90",@"105"],@[@"120",@"135"],@[@"180",@"215"],@[@"260",@"305"],@[@"350",@"360"]]];
-
- _arrAngle = @[@[@[@"0",@"45"],@[@"45",@"90"],@[@"90",@"135"],@[@"135",@"180"],@[@"180",@"225"],@[@"225",@"260"],@[@"260",@"305"],@[@"305",@"350"],@[@"350",@"360"]]];
-
-
- [self statGetStartShop];
- }
-
- return self;
- }
- - (void)statGetStartShop{
-
- [SVProgressHUD show];
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
-
- [g_server getUseract_act_getTurntable:salt andToView:self];
- }
- - (void)playButtonPressed:(UIButton *)sender
- {
-
- int selectIndex = (int)(1 + (arc4random() % (7)));
- NSLog(@"抽奖结果 %d",selectIndex);
-
- long time = (long)[[NSDate date] timeIntervalSince1970];
- time = (time *1000 + g_server.timeDifference);
- NSString *salt = [NSString stringWithFormat:@"%ld", time];
- //卷盘抽奖
- [g_server getUseract_turntableDo:salt andToView:self];
-
- LotteryItem *item = [[LotteryItem alloc] init];
- item.time = [NSNumber numberWithDouble:0.2];
- item.selectIndex = selectIndex;
- item.angle = [self getAngle:0];
- [self lotteryAction:item];
- }
- - (int)getAngle:(int)index
- {
- NSArray* arr = [_arrAngle objectAtIndex:index];
- //int x = arc4random() % arr.count;
- int x = (int)(1 + (arc4random() % (arr.count)));
-
- NSArray* arrJu = [arr objectAtIndex:x];
- int angle = arc4random() % ([[arrJu objectAtIndex:1] intValue] - [[arrJu objectAtIndex:0] intValue]) + [[arrJu objectAtIndex:0] intValue];
-
-
- return x*M_PI/4;
- }
- - (void)lotteryAction:(LotteryItem*)item
- {
-
- if([item.time doubleValue] > 2)
- {
- if(item.angle > 180)
- {
- [UIView animateWithDuration:[item.time doubleValue] animations:^{
- self.rotalIMG.transform=CGAffineTransformMakeRotation(180*M_PI/180);
- }];
- }
- [UIView animateWithDuration:[item.time doubleValue] animations:^{
- _vLine.transform=CGAffineTransformMakeRotation(item.angle*M_PI/180);
- }];
- }
- else
- {
- [UIView animateWithDuration:[item.time doubleValue] animations:^{
- self.rotalIMG.transform=CGAffineTransformMakeRotation(180*M_PI/180);
- }];
-
-
- [UIView animateWithDuration:[item.time doubleValue] animations:^{
- self.rotalIMG.transform=CGAffineTransformMakeRotation(360*M_PI/180);
- }];
-
-
- NSNumber* _D = [NSNumber numberWithDouble:[item.time doubleValue] + 0.2];
-
- LotteryItem* _item = [[LotteryItem alloc] init];
- _item.time = _D;
- _item.angle = item.angle;
-
- [self performSelector:@selector(lotteryAction:) withObject:_item afterDelay:[item.time doubleValue] - [item.time doubleValue] / 2];
- }
- }
- /**
- * 返回数据结果
- */
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
-
- [SVProgressHUD dismiss];
- if([aDownload.action isEqualToString:act_getTurntable])//获取展示奖品
- {
- NSMutableArray *jpDataArr=[awarJpModel mj_objectArrayWithKeyValuesArray:array1];
-
- [self createAllBtn:jpDataArr];
- }
- if([aDownload.action isEqualToString:act_turntableDo])//获取展示奖品
- {
-
- int aaaaaa=[dict[@"rewardCode"] intValue];
- [self choujiangResult:aaaaaa];
- }
-
- }
- - (void)choujiangResult:(int )selectAAaa{
- int selectIndex = (int)(selectAAaa + (arc4random() % (12)));
- selectIndex = selectAAaa;
-
- }
- /**获取抽奖数据*/
- - (void)createAllBtn:(NSMutableArray *)dataArr{
-
- dispatch_async(dispatch_get_main_queue(), ^{
- for (int i = 0; i <dataArr.count; i ++) {
-
- awarJpModel *model=dataArr[i];
- UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,M_PI * CGRectGetHeight(self.bounds)/8,
- CGRectGetHeight(self.bounds)/2)];
- label.layer.anchorPoint = CGPointMake(0.5, 1);
- label.center = CGPointMake(CGRectGetHeight(self.bounds)/2, CGRectGetHeight(self.bounds)/2);
- label.text = [NSString stringWithFormat:@"%@",model.rewardNum];
- CGFloat angle = M_PI * 2 / 8 * i;
- label.textAlignment = NSTextAlignmentCenter;
- label.font = [UIFont systemFontOfSize:12];
- label.transform = CGAffineTransformMakeRotation(angle);
- [self.rotalIMG addSubview:label];
-
- UILabel *labelText = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, M_PI * CGRectGetHeight(self.bounds)/8 - 20, 40)];
- labelText.text = model.rewardName;
- labelText.font = [UIFont systemFontOfSize:10];
- labelText.numberOfLines = 2;
- labelText.textAlignment = NSTextAlignmentCenter;
- [label addSubview:labelText];
- }
-
- });
-
-
- }
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
-
- [SVProgressHUD dismiss];
- NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
- if([errorCode isEqualToString:@"权限验证失败"])
- {
- }
- self.jiantouBtn.userInteractionEnabled=YES;
- return 1;
- }
- @end
|