Loginbonus.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //
  2. // Loginbonus.m
  3. // yunbaolive
  4. //
  5. // Created by Rookie on 2017/4/1.
  6. // Copyright © 2017年 cat. All rights reserved.
  7. //
  8. #import "Loginbonus.h"
  9. #import "LogFirstCell.h"
  10. #import "LogFirstCell2.h"
  11. #import <YYText/YYLabel.h>
  12. #import <YYText/NSAttributedString+YYText.h>
  13. static NSString* IDENTIFIER = @"collectionCell";
  14. static NSString *IDENTIFIER2 = @"collectionCell2";
  15. @interface Loginbonus ()<UICollectionViewDelegate,UICollectionViewDataSource>
  16. {
  17. CADisplayLink *_link;
  18. LogFirstCell *selectCell;
  19. LogFirstCell2 *selectCell2;
  20. UIImageView *sevendayimageview;
  21. NSString *logDayCount;
  22. NSString *logis_bonus;
  23. NSString *logDay;
  24. NSArray *numArr ;
  25. UIView *whiteView;
  26. UIImageView *backImg;
  27. UIView *firtBackView;
  28. }
  29. @property (nonatomic,strong) NSArray *arrays;
  30. @end
  31. @implementation Loginbonus
  32. //#define speace 8*_window_width/375
  33. #define itemWidth 58
  34. #define itemHeight 75
  35. #define speace ((_window_width*0.96*0.7)-itemWidth*4)/4
  36. /****************** 登录奖励 -> ********************/
  37. -(instancetype)initWithFrame:(CGRect)frame AndNSArray:(NSArray *)arrays AndDay:(NSString *)day andDayCount:(NSString *)dayCount andIsBonus:(NSString *)isbonus{
  38. self = [super initWithFrame:frame];
  39. if (self) {
  40. self.backgroundColor = [UIColor clearColor];
  41. _arrays = arrays;
  42. logDay = day;
  43. logDayCount = dayCount;
  44. logis_bonus = isbonus;
  45. firtBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
  46. firtBackView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
  47. [self addSubview:firtBackView];
  48. [self firstLog:frame];
  49. }
  50. return self;
  51. }
  52. -(void)firstLog:(CGRect)frame {
  53. CGFloat height = _window_width *0.9*26/66.00+80+(_window_width *0.9*0.88 - 30)/4*(140/116.00)*2.5;
  54. backImg = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.02, -_window_height, _window_width*0.96, height)];
  55. backImg.userInteractionEnabled = YES;
  56. backImg.image = [UIImage imageNamed:getImagename(@"loginbonus_bg")];
  57. [self addSubview:backImg];
  58. UIButton *btn = [UIButton buttonWithType:0];
  59. btn.frame = CGRectMake(backImg.width*0.8, 0, 30, 30);
  60. [btn setImage:[UIImage imageNamed:@"loginclose"] forState:0];
  61. [btn addTarget:self action:@selector(cancelLQ) forControlEvents:UIControlEventTouchUpInside];
  62. [backImg addSubview:btn];
  63. CGFloat fcW = backImg.width;
  64. CGFloat fcH = backImg.height;
  65. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  66. layout.minimumLineSpacing = 5;
  67. layout.minimumInteritemSpacing =5;
  68. _firstCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(fcW *0.15 , backImg.height*0.4, fcW*0.7, fcH *0.4) collectionViewLayout:layout];
  69. _firstCollection.dataSource = self;
  70. _firstCollection.delegate = self;
  71. UINib *nib = [UINib nibWithNibName:@"LogFirstCell" bundle:nil];
  72. [_firstCollection registerNib:nib forCellWithReuseIdentifier:IDENTIFIER];
  73. UINib *nib2 = [UINib nibWithNibName:@"LogFirstCell2" bundle:nil];
  74. [_firstCollection registerNib:nib2 forCellWithReuseIdentifier:IDENTIFIER2];
  75. _firstCollection.backgroundColor = [UIColor whiteColor];
  76. [backImg addSubview:_firstCollection];
  77. NSString *str = YZMsg(@"已连续签到");
  78. CGFloat strWidth = [PublicObj widthOfString:str andFont:[UIFont systemFontOfSize:12] andHeight:24];
  79. if (![lagType isEqual:ZH_CN]) {
  80. strWidth += 20;
  81. }
  82. // UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(backImg.width/2-strWidth/2, _firstCollection.top-35, strWidth, 24)];
  83. UILabel *title = [[UILabel alloc]init];
  84. title.layer.cornerRadius = 13;
  85. title.layer.masksToBounds = YES;
  86. title.backgroundColor = [UIColor whiteColor];
  87. title.font = [UIFont systemFontOfSize:11];
  88. title.textColor = [UIColor blackColor];
  89. title.textAlignment = NSTextAlignmentCenter;
  90. title.backgroundColor = RGBA(255,46,140,0.1);
  91. [backImg addSubview:title];
  92. [title mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.centerX.equalTo(backImg);
  94. make.bottom.equalTo(_firstCollection.mas_top).offset(-11);
  95. make.width.mas_equalTo(strWidth+30);
  96. make.height.mas_greaterThanOrEqualTo(26);
  97. }];
  98. NSMutableAttributedString *textAtt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ %@ %@",YZMsg(@"已连续签到"),logDayCount,YZMsg(@"天")]];
  99. [textAtt addAttribute:NSForegroundColorAttributeName value:RGB_COLOR(@"#323232", 1) range:textAtt.yy_rangeOfAll];
  100. NSRange clickRange = [[textAtt string] rangeOfString:logDayCount];
  101. [textAtt yy_setTextHighlightRange:clickRange color:RGB_COLOR(@"#FF2E8C", 1) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  102. }];
  103. title.attributedText = textAtt;
  104. UILabel *tipslb = [[UILabel alloc]init];
  105. // tipslb.frame = CGRectMake(0, title.top-28, backImg.width, 20);
  106. tipslb.textAlignment = NSTextAlignmentCenter;
  107. tipslb.text = YZMsg(@"连续签到领取额外奖励");
  108. tipslb.font = [UIFont boldSystemFontOfSize:16];
  109. tipslb.textColor = RGB(255,88,120);
  110. tipslb.numberOfLines = 0;
  111. [backImg addSubview:tipslb];
  112. [tipslb mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.bottom.equalTo(title.mas_top).offset(-8);
  114. make.width.lessThanOrEqualTo(backImg.mas_width).multipliedBy(0.7);
  115. make.centerX.equalTo(backImg);
  116. }];
  117. UIButton *receiveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  118. CGFloat btnW = backImg.width*0.6;
  119. CGFloat btnH = 40;
  120. CGFloat btnX = backImg.width*0.2;
  121. CGFloat btnY = 10;
  122. receiveBtn.frame = CGRectMake(btnX, _firstCollection.bottom+5, btnW, btnH);
  123. receiveBtn.backgroundColor =RGBA(198,63,243,1);// Normal_Color;
  124. [receiveBtn addTarget:self action:@selector(clickReceiveBtn) forControlEvents:UIControlEventTouchUpInside];
  125. [receiveBtn setTitle:YZMsg(@"立即签到") forState:UIControlStateNormal];
  126. receiveBtn.titleLabel.textColor = [UIColor whiteColor];
  127. receiveBtn.layer.cornerRadius = 20;
  128. receiveBtn.layer.masksToBounds = YES;
  129. // [receiveBtn setBackgroundImage:[UIImage imageNamed:@"startLive_back"]];
  130. receiveBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  131. [backImg addSubview:receiveBtn];
  132. if ([logis_bonus isEqual:@"1"]) {
  133. receiveBtn.backgroundColor =RGBA(191,191,191,1);// Normal_Color;
  134. [receiveBtn setTitle:YZMsg(@"已签到") forState:UIControlStateNormal];
  135. receiveBtn.userInteractionEnabled = NO;
  136. }
  137. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  138. dispatch_async(dispatch_get_main_queue(), ^{
  139. [UIView animateWithDuration:0.8 animations:^{
  140. backImg.frame = CGRectMake(_window_width*0.02, _window_height*0.2, _window_width*0.96, height);
  141. }];
  142. });
  143. });
  144. }
  145. - (void)showLogSucessAnimation{
  146. [backImg removeFromSuperview];
  147. backImg = nil;
  148. UIImageView *lightImageView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.25, _window_height/2-_window_width*0.125-50, _window_width*0.5, _window_width*0.5)];
  149. lightImageView.image = [UIImage imageNamed:@"logFirst_背景"];
  150. [self addSubview:lightImageView];
  151. CABasicAnimation* rotationAnimation;
  152. rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  153. rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
  154. rotationAnimation.duration = 2;
  155. rotationAnimation.cumulative = YES;
  156. rotationAnimation.repeatCount = 9999;
  157. [lightImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
  158. //放大效果,并回到原位
  159. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  160. //速度控制函数,控制动画运行的节奏
  161. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  162. animation.duration = 0.5; //执行时间
  163. animation.repeatCount = 1; //执行次数
  164. animation.autoreverses = NO; //完成动画后会回到执行动画之前的状态
  165. animation.fromValue = [NSNumber numberWithFloat:0.2]; //初始伸缩倍数
  166. animation.toValue = [NSNumber numberWithFloat:1.2]; //结束伸缩倍数
  167. UIImageView *headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(lightImageView.left, lightImageView.top-lightImageView.width/3, lightImageView.width, lightImageView.width/3)];
  168. headerImgView.image = [UIImage imageNamed:getImagename(@"logFirst_成功")];
  169. [self addSubview:headerImgView];
  170. UIImageView *coinImageView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.375, lightImageView.width*0.25+lightImageView.top, _window_width*0.25, _window_width*0.25)];
  171. coinImageView.image = [UIImage imageNamed:@"logFirst_钻石"];
  172. [self addSubview:coinImageView];
  173. [headerImgView.layer addAnimation:animation forKey:nil];
  174. [coinImageView.layer addAnimation:animation forKey:nil];
  175. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, coinImageView.bottom+5, _window_width, 22)];
  176. label.textColor = [UIColor whiteColor];
  177. label.font = [UIFont boldSystemFontOfSize:20];
  178. label.textAlignment = NSTextAlignmentCenter;
  179. NSDictionary *subdic = _arrays[[logDay intValue]-1];
  180. label.text = [NSString stringWithFormat:@"+ %@",minstr([subdic valueForKey:@"coin"])];
  181. [self addSubview:label];
  182. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  183. [label.layer addAnimation:animation forKey:nil];
  184. });
  185. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  186. [UIView animateWithDuration:0.5 animations:^{
  187. self.transform = CGAffineTransformMakeScale(0.01, 0.01);
  188. [UIView animateWithDuration:0.8 animations:^{
  189. firtBackView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
  190. [firtBackView removeFromSuperview];
  191. firtBackView = nil;
  192. }];
  193. } completion:^(BOOL finished) {
  194. if ([_delegate respondsToSelector:@selector(removeView:)]) {
  195. [_delegate removeView:nil];
  196. }
  197. }];
  198. });
  199. }
  200. -(void)clickReceiveBtn {
  201. YBWeakSelf;
  202. [YBNetworking postWithUrl:@"User.getBonus" Dic:nil Suc:^(int code, id info, NSString *msg) {
  203. if (code == 0) {
  204. [weakSelf showLogSucessAnimation];
  205. }else{
  206. [MBProgressHUD showError:msg];
  207. }
  208. } Fail:^(id fail) {
  209. [MBProgressHUD showError:YZMsg(@"网络错误")];
  210. }];
  211. }
  212. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  213. return 1;
  214. }
  215. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  216. return _arrays.count;
  217. }
  218. -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  219. UICollectionViewCell *cell;
  220. if (indexPath.row == 6) {
  221. LogFirstCell2 *cell2 = [collectionView dequeueReusableCellWithReuseIdentifier:IDENTIFIER2 forIndexPath:indexPath];
  222. cell = cell2;
  223. } else {
  224. LogFirstCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:IDENTIFIER forIndexPath:indexPath];
  225. cell1.layer.cornerRadius = 3;
  226. cell1.layer.masksToBounds = YES;
  227. NSDictionary *subdic = _arrays[indexPath.row];
  228. cell1.numL.text = [NSString stringWithFormat:YZMsg(@"第%@天"),minstr([subdic valueForKey:@"day"])];
  229. if([logis_bonus isEqual:@"1"]){
  230. if (indexPath.item < [logDay integerValue]) {
  231. cell1.bgIV2.backgroundColor = RGBA(255, 247, 250, 0.8);
  232. cell1.numL.alpha = 0.6;
  233. }else{
  234. cell1.contentView.backgroundColor = RGBA(255, 46, 140, 0.1);
  235. }
  236. }else{
  237. if (indexPath.item < [logDay integerValue]-1) {
  238. cell1.bgIV2.backgroundColor = RGBA(255, 247, 250, 0.8);
  239. cell1.numL.alpha = 0.6;
  240. }else{
  241. cell1.contentView.backgroundColor = RGBA(255, 46, 140, 0.1);
  242. }
  243. }
  244. //判断第几天
  245. if (indexPath.item == [logDay integerValue]-1) {
  246. //动画
  247. selectCell = cell1;
  248. }
  249. cell = cell1;
  250. }
  251. return cell;
  252. }
  253. - (void)keepRatate {
  254. if ([logDay integerValue] == 7) {
  255. selectCell2.bgIV2.transform = CGAffineTransformRotate(selectCell2.bgIV2.transform, M_PI_4 * 0.02);
  256. }else {
  257. selectCell.bgIV2.transform = CGAffineTransformRotate(selectCell.bgIV2.transform, M_PI_4 * 0.02);
  258. }
  259. }
  260. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  261. if (indexPath.row == 6) {
  262. return CGSizeMake(itemWidth*2, itemHeight);
  263. }else {
  264. return CGSizeMake(itemWidth, itemHeight);
  265. }
  266. }
  267. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  268. NSLog(@"%zi",indexPath.item);
  269. }
  270. - (void)cancelLQ{
  271. [self.delegate removeView:nil];
  272. }
  273. /****************** <- 登录奖励 ********************/
  274. @end